How to Remove Old and Unused Docker Images?

Better Stack Team
Updated on August 1, 2022

Since the docker version 1.13 you can use the docker prune command to remove all dangling data such as containers stopped, volumes without containers, and images with no containers.

To remove dangling docker images you execute the following command:

 
docker image prune

You can also add an optional -a option to the command to remove all dangling as unused images. Unused, in this case, means unreferenced by another container

 
docker image prune -a

Docker before version 1.13

To remove dangling and unused docker images, you can use the following commands:

 
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →