Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not remove images even though no container is running

I had multiple stopped containers and images in my machine.
I wanted to clean up and removed all containers:
docker ps -a returns nothing.
I run docker rmi $(docker images -q) to remove the cached images but I get:

Error response from daemon: conflict: unable to delete ... (must be forced) - image is referenced in multiple repositories

What repositories is it talking about?

like image 407
Jim Avatar asked Nov 17 '18 19:11

Jim


People also ask

How do I force a docker to remove an image?

By running simple command docker images -a or docker images . After that you make sure which image want to remove, to do that executing this simple command docker rmi <your-image-id> . Then you can confirm that image has been removed or not by list all the images and check.

How do I get rid of a non running docker container?

It's possible to remove containers that aren't running? You can use the command docker container list --all to see all the container no matter the state, and then use the command docker rm containerName to delete the container.

Could not remove image as it is being used by containers?

This error occurs when you try to delete a docker image. This is because this image is being used by a container. Hence it is not allowing you to remove the image. To fix this, first remove the container that uses your docker image.


1 Answers

You cannot remove images having multiple repositories without the force modifier, see Docker docs for more info.

docker images REPOSITORY                   TAG      IMAGE ID            CREATED           SIZE repository/image-name        tag      a8e6fa672e89        10 days ago         344MB repository2/image-name       tag      a8e6fa672e89        10 days ago         344MB 

If you want to do it manually, instead of using the image id to remove the images, you must remove the repository/tag that you don't need using image names:

docker rmi a8e6fa672e89 Error response from daemon: conflict: unable to delete a8e6fa672e89 (must be forced) - image is referenced in multiple repositories 

Remove the repository/tag you don't need:

docker rmi repository/image-name:tag Untagged: repository/image-name:tag Untagged: repository/image-name:tag@sha256:64b5a02e2bb3ee4d4b7c0982e8e2e5eb68bdfd0fb096fce22b6c030dafb53a33 

(Repeat last step until only one repository/tag remains) And now you will be able to remove the image:

docker rmi a8e6fa672e89 Untagged: repository2/image-name:tag Deleted: sha256:a8e6fa672e89b399bd3ac52b96c031e6816a69191d1fd7e6a1839fd643e3c751 Deleted: sha256:9861dd7b5783217515f571fdcfa6729e1e38af3ae9c971026e5a317b12fc5905 

If you use the -f flag and specify the image’s short or long ID, then rmi untags and removes all images that match the specified ID.

like image 113
Gabriel Avatar answered Sep 23 '22 03:09

Gabriel