Cannot remove images even though no container is running
Asked Answered
M

13

138

I had multiple stopped containers and images on my machine.
I want to clean up and remove 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 this talking about?

Mesics answered 17/11, 2018 at 19:1 Comment(3)
you can try to call it with force option (-f): docker rmi -f $(docker images -q)Astatic
Here you can find a hint for it: github.com/portainer/portainer/issues/497 github.com/moby/moby/issues/1530 it looks like if you have multiple tags on the same image docker will get back with such message.Astatic
For future refernces the repositories mentioned in the error above are the ones which are found in docker hub.When you create a docker image and push it to docker hub it creates a repositoryInna
C
161

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.

Crosswalk answered 15/3, 2019 at 9:33 Comment(1)
This worked for me with a small twist - I had dangling images with no tag, but two repositories. I had to first docker tag them.Dowden
T
35

The "repositories" it is talking about is part of the first column of a docker images:

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

(I take the samples which Gabriel showed in his answer)

Here we have two repositories: "repository" and "repository2". As you also can see, both images have the same IMAGE ID.

A docker images -q lists all available IMAGE ID's. Thus if you want to remove an IMAGE ID which is referenced by two images you get the error that you have mentioned.

Solution: You can remove the image by its name instead of its ID:

docker rmi repository/image-name:tag
Tuberose answered 25/5, 2020 at 10:8 Comment(1)
Thank you, this helped me. I wanted to combine this with a custom filter. Using docker images -q returns IDs by default. Following your comment I added a --format argument, ending up with the following: docker rmi $(docker image ls --filter "label=lu.ptech.bb.built-by=malbert" --format "{{.Repository}}:{{.Tag}}")Kristinakristine
S
22

To remove a Docker image forcefully, which is referring to multiple repositories, just use the command:

sudo docker rmi -f image_id
Selfhypnosis answered 16/2, 2021 at 4:3 Comment(0)
W
9

The underlying problem is that you are trying to remove the image, but the image is tagged as Tarun Banda wrote. So don't delete the image by its id, but by its tag. That will untag the image, and then delete it.

Here an example to cleanup old containers:

docker images | grep '3 weeks ago' | awk '{print $1 ":" $2}' | xargs -n 1 docker rmi
Westley answered 12/9, 2021 at 22:38 Comment(0)
H
6

You can clean up all containers. First of all, you need to stop all containers with: docker stop $(docker ps -aq). Finally, remove all containers with: docker rm $(docker ps -aq). You can do it all in one command docker rm $(docker stop $(docker ps -aq)).

If you want to remove all containers data:

docker container prune
docker network prune
docker system prune
docker volume prune
docker builder prune
Holter answered 19/7, 2020 at 16:55 Comment(0)
S
4

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

If this error is coming first untag the image and then it can be deleted. This can be done by using thee following command. docker rmi :<image_tag>

Spitball answered 20/5, 2021 at 10:14 Comment(1)
Please add tags to you question and tell more about language you usedThanatopsis
P
3

If you are sure you want to remove all your images, you can use this command:

docker images | awk '{print $1":"$2}' | egrep -E 'REPOSITORY|TAG' | xargs -n1 docker rmi
Predicative answered 23/1, 2020 at 14:19 Comment(0)
L
3

to delete a single record : sudo docker rmi -f <image_name>

to delete all images:
sudo docker rmi -f $(sudo docker images -a -q)

The "-f" parameter is important

Lamebrain answered 6/1, 2021 at 9:57 Comment(1)
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Phyla
H
0

If you want to remove you image from docker which is not going in cleanup process, just right below command:

docker image rm "image id" --force

it work for me.

Hummer answered 12/9, 2023 at 9:6 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Aldarcy
A
0

One liner to remove images referenced in multiple repositories:

docker rmi $(docker images -q) 2>&1 |grep conflict |cut -d "(" -f1 |cut -d " " -f9 |xargs docker rmi -f || true
Antiquated answered 11/11, 2023 at 15:24 Comment(0)
A
0

docker image rm REPOSITORY:TAG

Anzus answered 20/11, 2023 at 14:11 Comment(1)
Hi david cung, why do you think this will solve the problem described in the question? If you do not add any reasoning, this answer will not help.Yare
I
0

For future refernce if you encounter such an issue here is how you can go about it.

docker rmi 1b0d44d69609 --force

The referenced number 1b0d44d69609 is the image id or IMAGE ID in docker command line.

You can also reference from this docs docker remove image

Inna answered 12/3, 2024 at 13:33 Comment(0)
E
-1
 docker rmi `docker images --format="{{.Repository}}:{{.Tag}}"`
Excusatory answered 4/1, 2021 at 18:51 Comment(2)
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From ReviewWeekly
@AbhinavGupta it does. Delete images by repository uri and tag instead of image id, because as the error message says image is referenced in multiple repositories.Excusatory

© 2022 - 2025 — McMap. All rights reserved.