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

The 12 Days of Christmas - ITB 2022 Video Release— Day 2 - New Modules

The 12 Days of Christmas - ITB 2022 Video Release— Day 2 - New Modules

It's that time of year again. Trees are lit, presents are being wrapped, and relatives are coming to visit. That's right, it's time again for the 12 days of Christmas-- 2022 ITB Video Release Edition! 

Today, Day 2's Videos from Into the Box 2022 Conference, are all newly announced modules.

Gavin Pickin
Gavin Pickin
December 09, 2022
The 12 Days of Christmas - ITB 2022 Video Release— Day 1

The 12 Days of Christmas - ITB 2022 Video Release— Day 1

It's that time of year again.  Trees are lit, presents are being wrapped, and relatives are coming to visit.  That's right, it's time again for the 12 days of Christmas-- 2022 ITB Video Release Edition!

For the next 12 business days up until Christmas, we'll be releasing a series of related videos each day on the CFCasts site for our CFCasts Subscribers, and a announcement with titles, descriptions, and links to the videos, right here on the Ortus blog.  Consider it our early Christmas gift to you.

Gavin Pickin
Gavin Pickin
December 08, 2022
CommandBox Docker v3.6.3 Images Released

CommandBox Docker v3.6.3 Images Released

CommandBox 3.6.3 Docker images released



Today we are pleased to announce the release of version 3.6.3 of our CommandBox Docker images, which contains significant upgrades to the underlying CommandBox engine.

Most significantly, this release upgrades the CommandBox binary to 5.7.0. Read the Release Notes for this version here. This image version also adds new distro builds for the RHEL Universal Base Image. These images may be utilized by using the ubi9 in the image tag in the same way the alpine base images currently do.

Jon Clausen
Jon Clausen
December 08, 2022