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

Into the Box Round 1 of Sessions and Workshops are now out!

Into the Box Round 1 of Sessions and Workshops are now out!

Our first round of sessions and workshops for Into the Box 2025 is here! Get ready to dive into a world of modern web development with hands-on workshops and engaging sessions led by Ortus Solutions and Community CFML and BoxLang experts. Visit intothebox.org to explore what’s in store—this is just the beginning, with much more content coming soon!

Maria Jose Herrera
Maria Jose Herrera
January 20, 2025
BoxLang 1.0.0 Beta 26 Launched

BoxLang 1.0.0 Beta 26 Launched

We’re thrilled to announce the release of BoxLang 1.0.0 Beta 26, a monumental update that takes performance and functionality to the next level. This beta officially certifies the ColdBox HMVC Framework to run on BoxLang, marking a significant milestone in compatibility. Not only can you now run all ColdBox applications seamlessly on BoxLang, but with the latest ColdBox snapshot, you can also build your entire applications in BoxLang, unlocking the full potential of this dynamic and expressive language for modern application development.

Luis Majano
Luis Majano
January 20, 2025