Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (2.3k points)

New to docker here, I have been playing around with a ubuntu based docker container, it was a good learning experience but when i tried to remove the image it using the docker rmi I keep get this error:

Error response from daemon: conflict: unable to remove repository reference "ubuntu" (must force) - container 65c315b169b8 is using its referenced image 747cb2d 60bbe

Is it fine for me to use the '--force' flag to remove the image like this?:

$ sudo docker rmi ubuntu --force

is there a better or more standard procedure to remove the image?

1 Answer

0 votes
by (6.9k points)

The answer is that yes you can remove the image using the '--force' flag to remove the image but it will only untag the image as the image layers are still being used by the container to run.

So if you want to delete an image properly use this script:

containerIds=$(docker ps -a | grep "$<imageName>" | awk '{ print $1 }')
docker stop $<containerIds>
docker rm $<containerIds>
docker rmi "$<imageName>"

 This should first stop the containers making use of the image you want to delete and then it will remove all those containers and then remove the image.

Learn how to work with docker images & containers better with docker training course online.

Browse Categories