Docker list containers by name or id with filter

Docker list containers by name or id with filter

3 minutes 2s
How to list available containers in two ways: by container name or by container id. The same technique works for any other field listed about the container.

Listing Docker containers by name

We can use the filter option to filter by any field

sudo docker container ls -a --filter "name=test"
    
    
    

Listing Docker containers by container id

We use the same logic as above to filter by id

sudo docker container ls -a --filter "id=aebdb5b15af4"
    
    
    

Option 1: Showing all containers

sudo docker ps -a
    
    
    

Option 2: Showing all containers

sudo docker container ls -a
    
    
    

Output

$ sudo docker ps -a
    CONTAINER ID   IMAGE          COMMAND                  CREATED       STATUS                   PORTS     NAMES
    aebdb5b15af4   shortvideos    "/bin/bash"              6 hours ago   Exited (0) 5 hours ago             shortvideos
    d091d8ef32df   5144a558dd2d   "/bin/sh -c 'sudo ap…"   2 days ago    Exited (1) 2 days ago              bold_booth
    d18ddc78d9cc   4dd79dc77086   "/bin/sh -c 'adduser…"   2 days ago    Exited (1) 2 days ago              nice_hertz
    0c714ca39b6d   cee4c80266eb   "/bin/sh -c 'adduser…"   2 days ago    Exited (1) 2 days ago              sad_chebyshev
    9cc13ba45331   ubuntu         "bash"                   2 days ago    Exited (0) 2 days ago              agitated_pasteur
    
    

Notes

• sudo docker ps --filter option
https://docs.docker.com/engine/reference/commandline/ps/#filtering

• sudo docker container option
https://docs.docker.com/engine/reference/commandline/container/

• Docker official documentation
https://docs.docker.com/