DEV Community

GaMa
GaMa

Posted on • Edited on

3 1

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).

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (2)

Collapse
 
champkeh profile image
champ • Edited

why try this:

docker image prune

or

docker image prune -f
Collapse
 
ech0server profile image
GaMa

This is awesome, did not know it existed, thank you I will update my post !! :)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs