Docker – How to Remove Tagged Images

When working with Docker over time, your local environment can get cluttered with many tagged images — sometimes from testing, sometimes from old builds you no longer need. Removing these unused images keeps your system clean and frees up disk space.

In this guide, we’ll cover how to safely remove tagged Docker images.


🔍 Understanding Tagged Images

A tag in Docker is simply a label pointing to a specific image version.

For example:

myapp:latest
myapp:v1.0

Here:

  • myapp is the repository name
  • latest and v1.0 are tags

🛠 Removing a Specific Tagged Image

To remove a specific image:

docker rmi repository:tag

Example:

docker rmi myapp:v1.0

If the image is being used by a running container, you’ll get an error:

Error response from daemon: conflict: unable to remove repository reference ...

Fix: Stop and remove the container first:

docker ps -a
docker stop <container_id>
docker rm <container_id>

Then retry removing the image.


🗑 Removing Multiple Tagged Images

You can remove multiple tagged images at once:

docker rmi image1:tag image2:tag

Or, using a filter to match certain tags:

docker images --filter=reference='myapp:*' -q | xargs docker rmi

This will remove all tags for myapp.


🧹 Removing All Tagged Images Except Latest

If you want to keep only the latest tag and delete the rest:

docker images --filter=reference='myapp:*' --format '{{.Repository}}:{{.Tag}}' \
| grep -v 'latest' | xargs docker rmi

⚠️ Forcing Removal

If an image is in use but you still want to delete it:

docker rmi -f repository:tag

⚠️ Warning: This will remove the image even if containers depend on it, which may cause them to fail.


📌 Best Practices

  1. Regularly prune unused images to save space: docker image prune (This only removes dangling images — not tagged ones.)
  2. For complete cleanup, including tagged and unused images: docker image prune -a Note: This deletes all unused images, so use with caution.
  3. Always confirm what you’re deleting: docker images

🚀 Final Thoughts

Managing tagged images is an important part of keeping your Docker environment organized. By removing old and unused tags, you can reduce disk usage and keep your builds cleaner and faster.

Sharing Is Caring:

Leave a Comment