Skip to main content

How to Remove a Docker Image

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

Images stay on your computer until you remove them, and they add up. docker rmi deletes an image you no longer need: its name first, then its layers that no other image uses. This guide removes an nginx image and checks it's gone, with real output from Docker Desktop 4.100.1.

Syntax​

Syntax
docker rmi IMAGE
PartWhat it means
IMAGEThe image's name and tag, such as nginx:alpine, or its ID

docker rmi is short for docker image rm. Its reference: "Removes (and un-tags) one or more images from the host node. If an image has multiple tags, using this command with the tag as a parameter only removes the tag. If the tag is the only one for the image, both the image and the tag are removed." The same command works in PowerShell.

Prerequisites​

Step 1: Remove the Image​

Terminal
docker rmi nginx:alpine
Output
Untagged: nginx:alpine
Untagged: nginx@sha256:7fc0fb4af7bf006aeb31aea88069976060f8f0a0a86b667126742cc17f4e31ae
Deleted: sha256:7f2d42982b61384c4808f31f7215d19db7ceed3056dc680b84be5790b0cb4c39
Deleted: sha256:a7246e8d4bdc990411663aaa3db487ce44cc97157f1a1f2fda49e24fa0a8a1e5
...
Deleted: sha256:d053941bd12affeec9c13e6e04c061518c8ba912e54423e338192ddea0bac01d

docker rmi nginx's output in a terminal: two Untagged lines, for the tag and the digest, and Deleted lines for the image and its layers.

  • Untagged: the names went first, the tag nginx:alpine and the digest it was downloaded by.
  • Deleted: then the image and its layers.

Step 2: Check It's Gone​

Terminal
docker images nginx
Output
IMAGE ID DISK USAGE CONTENT SIZE EXTRA

Only the header: no nginx image is left. The 68.5 MB it used are free again.

Common Mistakes​

MistakeWhat happensDo this instead
Removing an image a container still usesThe reference: "You cannot remove an image of a running container unless you use the -f option"Stop and remove the container first
Expecting docker rmi to remove it from Docker HubIt deletes your computer's copy onlyDocker Hub keeps its copy; docker pull brings it back

Troubleshooting​

SymptomLikely causeFix
Only Untagged lines, no DeletedThe image had another tag, so only this tag wentdocker images shows the other tags
Error response from daemon: No such imageThe name or tag is wrongCopy it from docker images

FAQ​

Can I remove several images at once?​

Yes: list them all after docker rmi, as the reference says, "one or more images".

Will a later docker run still work?​

Yes, if the image can be downloaded again: docker run pulls an image it doesn't find.

Conclusion​

docker rmi nginx:alpine untagged the image and deleted its layers, and docker images nginx came back with only its header.

Additional Resources​