As you work with Docker and build, pull, or tag images over time, your local Docker environment can quickly become cluttered with unused or outdated images. Keeping your Docker images clean is crucial for saving disk space, improving performance, and avoiding confusion. In this post, we’ll focus specifically on how to remove tagged images in Docker—both selectively and in bulk.
Understanding Docker Image Tags
In Docker, a tag is a human-readable alias for a specific image ID. For example:
myapp:latest
myapp:v1.0.0
These are both tagged images that refer to underlying image layers. Over time, you may accumulate many such tags, especially when versioning applications or pulling updates from registries.
List Docker Images with Tags
To view all images and their tags:
docker images
You’ll see output like:
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp latest a1b2c3d4e5f6 3 days ago 200MB
myapp v1.0.0 a1b2c3d4e5f6 3 days ago 200MB
Note that both tags (latest
and v1.0.0
) may point to the same image ID.
How to Remove a Tagged Image
🔹 Remove by Repository and Tag
You can remove a specific tagged image like this:
docker rmi myapp:v1.0.0
This removes the v1.0.0
tag. If other tags (e.g., latest
) still point to the same image ID, the image won’t be deleted—only the tag is removed.
🔹 Remove All Tags for an Image ID
To fully delete the image, ensure no tags are pointing to it:
docker rmi myapp:v1.0.0 myapp:latest
Or by image ID:
docker rmi a1b2c3d4e5f6
You can find the image ID using:
docker images --no-trunc
How to Remove Multiple Tagged Images
🔹 Remove by Pattern or Script
Let’s say you want to delete all versions of myapp
:
docker images "myapp" --format "{{.Repository}}:{{.Tag}}" | xargs docker rmi
This removes all tags under the myapp
repository.
🔹 Remove All Images with a Certain Prefix
docker images --format "{{.Repository}}:{{.Tag}}" | grep '^myapp:' | xargs docker rmi
This is helpful for batch cleanup during development.
Remove Dangling vs Tagged Images
- Dangling images: Images with no tag (i.e.,
<none>
), often leftovers from intermediate builds. - Tagged images: Have human-readable names and should be removed explicitly using their name/tag.
To remove only dangling images:
docker image prune
To remove all unused images, including tagged ones not used by any container:
docker image prune -a
⚠️ Use with caution: this deletes images not currently used by any container.
Force Removal of Tagged Images
If the image is currently being used by a running or stopped container, Docker will prevent deletion. To force-remove it:
docker rmi -f myapp:v1.0.0
Or for multiple tags:
docker rmi -f myapp:latest myapp:v1.0.0
Conclusion
Keeping your Docker environment clean is part of effective container management. Tagged images are useful for versioning and organization, but over time they can clutter your system. Use the Docker CLI to selectively or automatically remove tagged images, free up space, and simplify your workflow.
Quick Commands Summary
Action | Command |
---|---|
List all images | docker images |
Remove one tagged image | docker rmi myapp:v1.0.0 |
Remove multiple tags | docker rmi myapp:v1.0.0 myapp:latest |
Remove by image ID | docker rmi IMAGE_ID |
Remove images matching a pattern | docker images "myapp" --format "{{.Repository}}:{{.Tag}}" | xargs docker rmi |
Remove dangling images | docker image prune |
Remove all unused images | docker image prune -a |
Force delete in-use image | docker rmi -f myapp:tag |