Removing stopped docker containers and images

Over time it’s easy for the number of stopped docker containers to steadily increase. To periodically clean up the stopped containers:

$ docker rm $(docker ps --filter "status=exited" -q)
$ docker rm $(docker ps --filter "status=dead" -q)

To clear up their images, providing your setup is simple then you can remove all images, trusting docker not to remove any that are used by a running container:

$ docker rmi $(docker images -a -q)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.