Removing Docker Images and Fixing 'Image Is in Use' Errors
Step-by-step guide to removing local Docker images with docker image rm, understanding image reference dependencies, and resolving 'unable to delete... container is using image' errors.
Published on • November 18, 2026
AI Assistant

Deleting unused Docker images is a routine cleanup task to free up host disk space. However, running docker image rm (or docker rmi) often throws confusing errors such as unable to delete... image is being used by running container or conflict: unable to remove repository reference.
In this tutorial, we will explain how image reference removal works in Docker, why dependency conflicts occur, and how to safely resolve “image in use” errors without corrupting container state.
Basic Image Removal Syntax
To remove a local image by tag or Image ID:
docker image rm nginx:1.25
# or using the shortcut alias:
docker rmi 92b11f4d1571
If multiple tags point to the exact same Image ID (same content digest), removing one tag simply untags the reference without deleting underlying image layers:
Untagged: myapp:v1
Untagged: myapp:latest
Deleted: sha256:92b11f4d1571... (layers removed only when last tag is untagged)
Common “Image is in Use” Error Scenarios
Scenario 1: Stopped Containers Holding References
Error Message:
Error response from daemon: conflict: unable to delete 92b11f4d1571 (cannot be forced) - image is being used by stopped container 4a3e21f98c10
Why it happens: Even if a container is currently stopped (exited), its container configuration records the parent base Image ID. Docker prevents deleting the image layers so that the stopped container can be restarted later if needed.
Solution: Identify and remove the stopped container first, then remove the image:
# 1. Find the stopped container using the container ID from error
docker ps -a --filter "id=4a3e21f98c10"
# 2. Remove the stopped container
docker rm 4a3e21f98c10
# 3. Remove the image
docker image rm 92b11f4d1571
Or clean up all stopped containers in one command:
docker container prune -f
docker image rm 92b11f4d1571
Scenario 2: Active Running Containers
Error Message:
Error response from daemon: conflict: unable to delete 92b11f4d1571 (must be forced) - image is being used by running container b21a7c390f11
Why it happens: A container is currently running based on this image. Deleting the active image layers while processes are actively reading from them could crash running processes or cause storage driver corruption.
Solution: Stop and remove the container before deleting the image:
# 1. Stop the running container gracefully
docker stop b21a7c390f11
# 2. Remove the container
docker rm b21a7c390f11
# 3. Remove the image
docker image rm 92b11f4d1571
Scenario 3: Multiple Tags (Repository Reference Conflicts)
Error Message:
Error response from daemon: conflict: unable to remove repository reference "myapp:v1" (must be forced) - container 7f81a9c01d22 is using its referenced image 92b11f4d1571
Why it happens: The image ID has multiple tags assigned to it (e.g., myapp:v1 and myapp:latest), and a container references that ID.
Solution:
You can untag specific references using docker image rm <repo>:<tag>. If you want to force untagging without removing the active container:
# Force untagging a reference tag (leaves image ID intact for the container)
docker image rm -f myapp:v1
The Dangers of docker image rm -f (Force Removal)
Passing the -f / --force flag forces Docker to untag images and attempt immediate removal.
# WARNING: Use with caution
docker image rm -f 92b11f4d1571
Why you should avoid forcing image deletion indiscriminately:
- Force removal untags images referenced by running containers, turning their parent image reference into an orphaned
<none>:<none>digest. - If the container stops or restarts, it may fail to restart because its tagged reference was broken.
- It can leave orphaned layers behind in storage drivers like
overlay2.
Safe Diagnostic & Cleanup Workflow
To safely clean up unused images without encountering dependency errors:
# Step 1: Remove all exited/stopped containers first
docker container prune -f
# Step 2: Remove dangling (un-tagged intermediate) images
docker image prune -f
# Step 3: Remove all unused images not referenced by ANY existing container
docker image prune -a -f
Summary
| Conflict Type | Cause | Recommended Action |
|---|---|---|
| Stopped Container | Exited container references Image ID | Run docker rm <container_id> first |
| Running Container | Active container process depends on image | Run docker stop then docker rm |
| Multiple Tags | Image ID has multiple tag pointers | Untag specific tag using docker image rm <tag> |
| Dangling Layers | Intermediate un-tagged build layers | Run docker image prune |
Always clean up stopped containers before attempting to delete their underlying images to maintain a healthy Docker daemon storage environment.