Docker remove all images except one

3 points
Created by:

In this article we whould like to show how to delete all docker images except one.

Quick solution:

docker image rm -f $(docker images -a | grep -v "put_image_id_here" | awk 'NR>1 {print $3}')


docker image rm -f $(docker images -a | grep -v "c8562eaf9d81" | awk 'NR>1 {print $3}')

To get docker image ID we can run command:

# list all images
docker images

# list all images (with dangling images)
docker images -a


Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Docker - useful wiki posts

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂