List of only stopped Docker containers

Docker allows you to list running containers or all containers, including stopped ones.

This can be done with:

$ docker ps # To list running containers 

or

 $ docker ps -a # To list running and stopped containers 

Do we have a way to only list containers that were stopped?

+152
docker containers
May 14 '15 at 6:56
source share
3 answers

Only stopped containers can be listed with:

 docker ps --filter "status=exited" 

or

 docker ps -f "status=exited" 
+251
May 14 '15 at 6:56
source share

Typical command:

 docker container ls -f 'status=exited' 

However, in this list only one of the possible idle statuses will be indicated. Here is a list of all possible statuses:

  • created
  • restart
  • works
  • removal
  • was silent
  • came out
  • dead

You can filter multiple statuses by passing multiple status filters:

 docker container ls -f 'status=exited' -f 'status=dead' -f 'status=created' 

If you integrate this using an automatic cleanup script, you can associate one command with another with some bash syntax, display only the container identifier with -q , and restrict only containers that successfully complete the exit code filter:

 docker container rm $(docker container ls -q -f 'status=exited' -f 'exited=0') 

For more information on the filters you can use, see the Docker documentation: https://docs.docker.com/engine/reference/commandline/ps/#filtering

+24
Aug 4 '18 at 17:36
source share
 docker container list -f "status=exited" 

or

 docker container ls -f "status=exited" 

or

  docker ps -f "status=exited" 
+2
Aug 14 '19 at 4:28
source share



All Articles