Bootstrap FreeKB - Docker - Delete an image using the docker rmi command
Docker - Delete an image using the docker rmi command

Updated:   |  Docker articles

This assumes you have installed Docker on Linux and Docker is running.

A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).

Before deleting an image, you'll want to use the docker images command to return the list of images, like this.

docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
foo                 latest              105b54dc64f1        32 hours ago        196.7 MB
bar                 1.2.3               95ga44bc5582        2 weeks ago         967 B

 

And use the docker ps command to return the list of containers associated with the image, like this.

docker ps -a

CONTAINER ID     IMAGE              COMMAND                 CREATED         STATUS     PORTS     NAMES
d937372c09ab9    b939aa938add9913   "/docker-entrypoin..."  6 minutes ago   Created              my-container

 

Before delete the image, you'll probably want to use the docker rm command to delete the containers associated with the image.

 

 

The docker rmi command followed by the name:tag or ID of the image deletes the image. In this example, any of these commands would delete the "foo" image.

docker rmi foo
docker rmi foo:latest
docker rmi 105b54dc64f1

 

Any of these commands would delete the "bar" image.

docker rmi bar:1.2.3
docker rmi 95ga44bc5582

 

If prompted "unable to remove repository reference "foo" (must force) - container xxxxxxxx is using its refrenced image xxxxxx", the -f or --force option can be used to delete the image.

docker rmi --force 105b54dc64f1

 

Sometime like this should be displayed.

Untagged: foo:latest
Deleted: sha256:xxxxxxxxxxxxxxxxxxxxxxx
Deleted: sha256:xxxxxxxxxxxxxxxxxxxxxxx
Deleted: sha256:xxxxxxxxxxxxxxxxxxxxxxx
Deleted: sha256:xxxxxxxxxxxxxxxxxxxxxxx
Deleted: sha256:xxxxxxxxxxxxxxxxxxxxxxx

 

Reissuing the docker images command should now show that the image is no longer listed.

docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
bar                 latest              95ga44bc5582        2 weeks ago         967 B

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 88582a in the box below so that we can be sure you are a human.