Skip to content

How to Force Remove Docker Images

DodaTech 2 min read

In this tutorial, you'll learn about How to Force Remove Docker Images. We cover key concepts, practical examples, and best practices.

The Problem

Running docker rmi <image> fails with Error response from daemon: conflict: unable to delete ... (cannot be forced) - image is being used by running container or image is referenced in multiple repositories. You cannot delete images that are in use or have multiple tags.

Quick Fix

Step 1: Remove unused images with prune

Clean up all dangling (untagged) images:

docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:a1b2c3d4e5f6...

Step 2: Remove all unused images including intermediate ones

Remove images not used by any container:

docker image prune --all

Step 3: Force remove an image used by a stopped container

First remove the containers that depend on the image:

docker rm --force $(docker ps -aq --filter "ancestor=image-name")
docker rmi image-name

Then remove the image.

Step 4: Force remove an image by ID

Use --force to remove an image even with multiple references:

docker rmi --force a1b2c3d4e5f6

Step 5: Remove all images at once

Delete every image on the system:

docker rmi --force $(docker images -q)

Step 6: Clean everything at once

Remove all unused containers, images, networks, and cache:

docker system prune --all
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all images without at least one container associated
  - all build cache

Alternative Solutions

Remove images older than a certain age

Use filters to target old images:

docker image prune --all --filter "until=24h"

Remove dangling images selectively

Clean up only untagged images:

docker rmi $(docker images -f "dangling=true" -q)

Common Mistakes to Avoid

Removing images that are in use by running containers. This does not free space because the running container still references the image layers.

Forgetting to prune build cache. Images are only part of the disk usage. docker <a href="/design-patterns/builder/">builder</a> prune cleans up the build cache.

Removing base images that are shared by multiple projects. Check docker image ls to see which images are used by multiple tags before bulk removal.

Pro Tips

Use docker image prune --all --filter until=24h. Remove images older than 24 hours to keep recent ones for rollback while freeing space.

Use dive to analyze image layers. The dive tool shows each layer's size and content, helping identify what uses space: dive image-name.

Use docker system df to see disk usage breakdown. Get a summary of all Docker disk usage: docker system df shows images, containers, and build cache sizes.

Prevention

  • Tag images with descriptive names to avoid anonymous dangling images.
  • Run docker system prune weekly to free up disk space.
  • Use docker image prune --all before pulling new versions to keep the image list clean.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro