How to remove temporal untagged Docker images

ech0server

GaMa

Posted on February 23, 2018

How to remove temporal untagged Docker images

*Update, thanks to champkeh

The correct way to remove unused docker images is using:

docker image prune [OPTIONS]

For more information you can go to:

https://docs.docker.com/engine/reference/commandline/image_prune/


If you have some experience with Docker you will know that mistakes are made while building your own images. At the beginning I didn't cared to delete one untagged image from time to time by using the docker rmi ###### command, however, when I had to work on a project to migrate a legacy application to Docker, I realized that there are a LOT of images just hanging out in the ether like "we are here just chillin".

chillin

So, I started doing some cleanup one by one, until, you know, who wants to paste the image id or the name to delete it? Right. Then I came up with the following one-liner:

docker images | awk '{if(match($1,"<none>")){print "docker rmi " $3 ";" | "/bin/sh"}}'

You can then add the line to a shell script or whatever.The good thing is that if by some reason an image has a dependen child (container associated to it) it won't delete it unless you force it (-f).

💖 💪 🙅 🚩
ech0server
GaMa

Posted on February 23, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related