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 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023