How to Remove Old Docker Containers?

Better Stack Team
Updated on August 1, 2022

You may have found docker rm command to remove a docker container. However, this works only for a single container and it would be very painful to run this command for every non-running docker container. Luckily, since Docker 1.13 there is a more elegant solution.

How to remove old Docker containers?

To remove all stopped containers, run the following command:

 
docker container prune

There is also system prune, which will clean up all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes, in one command.

 
docker system prune