Docker: Prune containers

When you stop a container, it is not automatically removed unless you started it with the --rm flag. In order to list all the containers running or stop run: docker ps -a. You may be surprised how many containers exist, especially on a development system!

In case you like to remove all the containers, first make sure you stop them all by running the following command.

Stop all containers

docker stop $(docker ps -a -q)

Stop all containers

Run following command to remove all the containers, regardless of how old are they.

docker container prune

By default, you are prompted to continue. To bypass the prompt, use the -f or --force flag.

By default, all stopped containers are removed. You can limit the scope using the --filter flag. For instance, the following command only removes stopped containers older than 24 hours:

docker container prune --filter "until=24h"

Other filtering expressions are available. See the docker image prune reference for more examples.

Author: Danyal
I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.