Docker Managing containers Listing containers

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
2bc9b1988080        redis               "docker-entrypoint.sh"   2 weeks ago         Up 2 hours          0.0.0.0:6379->6379/tcp    elephant-redis
817879be2230        postgres            "/docker-entrypoint.s"   2 weeks ago         Up 2 hours          0.0.0.0:65432->5432/tcp   pt-postgres

docker ps on its own only prints currently running containers. To view all containers (including stopped ones), use the -a flag:

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                     NAMES
9cc69f11a0f7        docker/whalesay     "ls /"                   26 hours ago        Exited (0) 26 hours ago                             berserk_wozniak
2bc9b1988080        redis               "docker-entrypoint.sh"   2 weeks ago         Up 2 hours                0.0.0.0:6379->6379/tcp    elephant-redis
817879be2230        postgres            "/docker-entrypoint.s"   2 weeks ago         Up 2 hours                0.0.0.0:65432->5432/tcp   pt-postgres

To list containers with a specific status, use the -f command line option to filter the results. Here is an example of listing all containers which have exited:

$ docker ps -a -f status=exited
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                     NAMES
9cc69f11a0f7        docker/whalesay     "ls /"                   26 hours ago        Exited (0) 26 hours ago

It is also possible to list only the Container IDs with the -q switch. This makes it very easy to operate on the result with other Unix utilities (such as grep and awk):

$ docker ps -aq
9cc69f11a0f7
2bc9b1988080
817879be2230

When launching a container with docker run --name mycontainer1 you give a specific name and not a random name (in the form mood_famous, such as nostalgic_stallman), and it can be easy to find them with such a command

docker ps -f name=mycontainer1



Got any Docker Question?