FreeKB - docker rmi command (delete an image)
Docker - docker rmi command (delete an image)

This assumes you have installed Docker on Linux and Docker is running. 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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments