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 a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.