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

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github