Skip to content

Docker list stopped containers

  • by
Docker list stopped containers

1. Overview

In this article, we will learn to list all stopped docker containers. You can learn more about docker by referring to these articles.

A docker image is a template or blueprint for containers. It is a sharable package with all the code, required tools, runtime, and dependencies to run that specific code. Containers are based on docker images and concrete running instances of images. Docker is a tool for creating and managing containers.

2. Docker list all stopped containers

You might already be familiar with the docker ps command to list the running containers.

The docker ps command only shows running containers by default. It

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS      NAMES
207ad40bbe73   5baa2684eb37   "docker-entrypoint.s…"   27 minutes ago   Up 27 minutes   8081/tcp   epic_bardeen

However, adding flags to this command would enable us to customize the behaviour. To see all containers, use the -a (or --all) flag with the docker ps command like below:

> docker ps -a

It lists all containers including stopped, running, and so on.

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                            PORTS                    NAMES
207ad40bbe73   5baa2684eb37   "docker-entrypoint.s…"   53 seconds ago   Up 51 seconds                     8081/tcp                 epic_bardeen
4dde333d7640   5baa2684eb37   "docker-entrypoint.s…"   3 minutes ago    Exited (137) About a minute ago                            frosty_joliot
6d12d35591f4   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (255) 6 weeks ago          0.0.0.0:8082->8081/tcp   vigorous_fermi
dccb12d24bdb   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                                   silly_knuth
4bc407c80d99   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (1) 6 weeks ago                                     pensive_leakey
0173039d404f   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                                   laughing_burnell
daccdfc13b81   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                                   awesome_rosalind

If you want to list only stopped containers, you can use the filtering flag (-f or --filter) of the docker ps command to filter the containers based on their status. The format of the filtering flag is a key=value pair.

The status filter matches containers by status. You can filter using createdrestartingrunningremovingpausedexited and dead. For example, to filter for exited \ stopped containers:

> docker ps -all --filter 'status=exited' 

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                        PORTS     NAMES
4dde333d7640   5baa2684eb37   "docker-entrypoint.s…"   32 minutes ago   Exited (137) 29 minutes ago             frosty_joliot

Alternatively, you can use the exited filter that matches containers by exist status code.

For example, if you want to filter all containers exited successfully.

docker ps -a --filter 'exited=0'

You can use a filter to locate containers that exited with an exit status of 137 meaning a SIGKILL(9) killed them. For example, stopping containers using docker stop also creates an exit status 137.

> docker ps -a --filter 'exited=137'
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS                        PORTS     NAMES
4dde333d7640   5baa2684eb37   "docker-entrypoint.s…"   36 minutes ago   Exited (137) 34 minutes ago             frosty_joliot
dccb12d24bdb   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                silly_knuth
0173039d404f   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                laughing_burnell
daccdfc13b81   9f356a6e96f4   "docker-entrypoint.s…"   6 weeks ago      Exited (137) 6 weeks ago                awesome_rosalind

3. Conclusion

To sum up, we have learned to list all stopped containers in the docker.

Leave a Reply

Your email address will not be published. Required fields are marked *