Blog

CONTAINERS2017 - Removing Docker Images

Luis Majano September 12, 2017

Spread the word

Luis Majano

September 12, 2017

Spread the word


Share your thoughts

We all need some help from time to time. The Docker CLI has an extensive suite of commands built-in and it can be painful to remember all of them. So as part of our containers roadshow, we will be blogging about useful tips and tricks for working with containers. We all make mistakes and we all need to be able remove images from time to time. So let's go ahead and start!

Remove one or more specific images

By using the docker images command with the -a flag, you can list all the images in the system by leveraging the image ID. Here is some example output:

$ docker images -a
REPOSITORY                         TAG                    IMAGE ID            CREATED             SIZE
<none>                             <none>                 178eecd0d35a        3 days ago          64MB
nginx_nginx                        latest                 56dab2b8fae4        3 days ago          64MB
<none>                             <none>                 e80436974f2f        3 days ago          64MB
<none>                             <none>                 bea15fa1eee1        3 days ago          64MB

Once you have located the image you want to wipe away pass the ID to the docker rmi command:

docker rmi ImageID

Removing Dangling Images

Please remember that docker images consist of multiple software layers. Dangling images are layers that have no relationships to any images or containers. Basically, orphaned images which still can cosume plenty of space. They can be located by adding the -f with a value of dangling=true to the docker images command. You can pass the -q flag to get a listing of image ID's and pass that to the rmi command for a nice concatenated removal:

# List
docker images -f dangling=true

# Remove them all baby
docker rmi $(docker images -f dangling=true -q)

Removing Images According to Patterns

You can get fancy by leveraging the grep command (in unix only) and the docker images command to get a nice listing according to patterns. Once you are golden with the images you want, you can then further pipe the command to awk to clean up the buffer and finally pass them to the rmi command.

# listing
docker ps -a |  grep "pattern"

#removing 
docker images | grep "pattern" | awk '{print $1}' | xargs docker rm

Removing All Images

Ok, we want to start fresh and cleany and minty fresh. Just use the following to remove all images

docker rmi $(docker images -a -q)

Don't drink and rmi.

Add Your Comment

(1)

Sep 13, 2017 20:48:09 UTC

by Justin Carter

You can also clean dangling images with; docker image prune Or for a full cleanup of images, containers, and optionally volumes (with an additional argument) docker system prune Full docs: https://docs.docker.com/engine/admin/pruning/

Recent Entries

ColdBox Training: From Hero to Superhero – Master ColdFusion and BoxLang Development

ColdBox Training: From Hero to Superhero – Master ColdFusion and BoxLang Development

Are you ready to take your ColdBox development skills for ColdFusion and BoxLang to the next level? Whether you're new to ColdBox or looking to sharpen your expertise, our ColdBox From Hero to Superhero training is the perfect opportunity to become a ColdFusion and BoxLang powerhouse.

Why Attend?

This hands-on training is designed to help ColdFusion and BoxLang developers level up their ...

Cristobal Escobar
Cristobal Escobar
February 19, 2025
Meet Raymond Camden: BoxLang Advocate!

Meet Raymond Camden: BoxLang Advocate!

We’re thrilled to announce that Raymond Camden, a leading voice in the CFML community, is joining us as a BoxLang Advocate. Currently collaborating with us as a contractor, Raymond brings years of web development experience and a passion for simplifying complex technologies. His expertise makes him the perfect advocate to explore BoxLang, a modern, CFML-compatible programming language.

Maria Jose Herrera
Maria Jose Herrera
February 19, 2025
Meet BoxLang at DevNexus 2025!

Meet BoxLang at DevNexus 2025!

We’re thrilled to announce that Ortus Solutions will be a Silver Sponsor at DevNexus 2025, one of the largest and most exciting Java conferences in the world! Our team will be on-site, spreading the word about BoxLang and its latest advancements, designed specifically to empower Java developers with dynamic, modular, and productive development capabilities.

Maria Jose Herrera
Maria Jose Herrera
February 19, 2025