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 skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk