Oops! Docker is showing the error unable to delete the image (must be forced). We can help you fix it.
Usually, this error shows up if a container is running in the image.
If there are no running containers we can forcefully remove the image.
At Bobcares, we often get requests to fix Docker errors, as a part of our Docker Hosting Support.
Today, our Support Engineers will provide clarification of deleting an image.
What is a Docker image and container?
Many newbies do not have a complete idea of Docker image and container. Hence, they end up in errors while building or managing it.
Docker images and containers are closely related. A running instance of an image is a container. In addition, we can have multiple running containers of one image.
Causes and fixes for the Docker error unable to delete image
Docker does not remove the used objects like containers, images, etc by its own. These unused objects can take up server space. So users remove them.
Here we will discuss the error showed up while removing a Docker image. The command to delete a Docker image is,
docker rmi <image_ID>
But this can often end up in the error unable to delete image must be forced. So let’s see a few instances where this error shows up.
Unable to delete an image as a container is running
Recently, one of our customers got an error while deleting an image. And the error message appeared as,
Error response from daemon: conflict: unable to remove repository reference "<IMAGE>" (must force) - container <container_ID> is using its referenced image <image_ID>
The error message specifies that a container is using the referred image. So our Support Engineers checked the containers and images in the server.
To list the containers we use the command,
docker ps -a
And to list the images we use the command,
docker images
Then we stop the container using the command
docker stop <container_ID>
Later we remove the container using the command,
docker rm <container_ID>
Finally, remove the image using the command,
docker rmi <image_ID>
This successfully removes the image.
Unable to delete an image used by a stopped container
Another customer had a slightly different situation. And the error message appears as,
Error response from daemon: conflict: unable to delete <image_ID> (must be forced) - image is being used by stopped container <container_ID>
Here the image is being used by a stopped container.
Since it is a stopped container, our Support Engineers forcefully removed it. Here we used the command,
docker rmi <image_ID> --force
Hence, this successfully removed the image. This situation appears as,
[Still, having trouble in fixing Docker errors? – Our Experts are available 24/7.]
Conclusion
In short, Docker error unable to delete image must be forced occur if some containers are running on it. If it is a stopped container we forcefully remove it. If not we stop and remove the container and delete the image. Today, we saw two instances where our Support Engineers fixed this error.
thank YOU!