Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker rmi cannot remove images, with: no such id

Tags:

docker

I have a lot of images. When I try to remove them with docker rmi

$ sudo docker rmi acd33a9490dc
Error response from daemon: No such id: 75ce1f6710bab109a7d7cbee056fa8a0c7fa913e81c88e2a55121149dda80ee9
2014/07/14 10:13:24 Error: failed to remove one or more images

That 75ce1... hash is the same no matter which docker image I try to remove.

At present, the below gives the current docker version; however some of these images have been around since an earlier version (0.6 or so)

$ sudo docker version
Client version: 1.0.1
Client API version: 1.12
Go version (client): go1.2.1
Git commit (client): 990021a
Server version: 1.0.1
Server API version: 1.12
Go version (server): go1.2.1
Git commit (server): 990021a
like image 497
Ben Clifford Avatar asked Jul 14 '14 09:07

Ben Clifford


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 remove a docker image with tag none?

docker image prune removes all dangling images (those with tag none). docker image prune -a would also remove any images that have no container that uses them.

How do I delete an image that is referenced in multiple repositories?

You cannot remove images having multiple repositories without the force modifier, see Docker docs for more info. 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.

Does docker RMI Remove from registry?

This does not remove images from a registry. You cannot remove an image of a running container unless you use the -f option. To see all images on a host use the docker image ls command.

Why can't I remove a docker image by its ID?

Which means you're trying to remove an image by its ID, however the image is tagged under multiple names. Docker then refuses to remove the image, because it would remove multiple image in a single remove. You can still remove the individual images by name. If you don't have containers running, you can --force delete the image in that case.

Can I use Docker image RM--force after stopping the container?

Note that we could use docker image rm --force after stopping the container but this is typically not required and might result in additional risks for other containers, e.g. if other images depend on said image. Since docker uses layered images.

Why can't I delete the image in the container I'm running?

There is currently a container running that uses the image you are trying to delete. We will solve this issue by first stopping the container and then deleting the image. Warning: Deleting the image is dangerous since you cannot undo deleting the image ! Also note that force-stopping a running container might result in data loss if ...

How do I remove all untagged containers in Docker?

To quickly remove any untagged containers (ones that show up as <none> <none> when you run sudo docker images) you can run the following command: I have saved that in /usr/local/bin/docker-purge-dangling so I can run it without needing to remember the command.


Video Answer


8 Answers

Put in your terminal:

docker ps -a

CONTAINER ID | IMAGE ......................NAMES

d25c0cd9725a |acd33a9490dc ................focused_einstein

You can see your IMAGEID in the column IMAGE. Get the CONTAINER ID an remove the container:

docker rm d25c0cd9725a

And now you can remove the image:

docker rmi acd33a9490dc
like image 161
jripoll Avatar answered Oct 02 '22 06:10

jripoll


If you need to remove several images, then you can delete all containers with

sudo docker ps -a -q | xargs -n 1 -I {} sudo docker rm {}

Now you can remove any images.

like image 28
Andras Hatvani Avatar answered Oct 02 '22 07:10

Andras Hatvani


I think this is the expected behavior, not a bug. This is because you have containers hanging around that have not been deleted. These containers are instances of the image, and that is preventing you from dropping that image.

Step 1 - remove unused container instances

Both jripoll's answer and Andras Hatvani's answer show ways of listing and removing the containers that are bound to the images.

Note that the latter will delete all container instances!! So, if there is one that you need to commit as a new image, you should do that first.

Step 2 - remove unnecessary images

After the containers have been deleted, you will be able to remove any images they were based on.

To quickly remove any untagged containers (ones that show up as <none> <none> when you run sudo docker images) you can run the following command:

    sudo docker images -q --filter "dangling=true" | sudo xargs docker rmi

I have saved that in /usr/local/bin/docker-purge-dangling so I can run it without needing to remember the command.

like image 42
Damon Avatar answered Oct 02 '22 06:10

Damon


You may also face this issue if you do not remove exited containers. You need to remove the exited container by doing this,

sudo docker ps -a | grep Exit | awk '{print $1}' | sudo xargs docker rm 

Then remove your image using

sudo docker rmi <imageID>
like image 39
Sohan Avatar answered Oct 02 '22 08:10

Sohan


First you need to locate the container holding the image.

To remove a single container with the image

docker ps -a

You will get such an output

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
g7aea2132441        2285ff53ab18        "/bin/bash"         2 days ago                                                  tombrider 

Then remove the container using

docker rm g7aea2132441

To remove all the containers and images do

  1. Remove all the containers

    docker stop $(docker ps -a -q)
    docker rm $(docker ps -a -q)
    
  2. Remove the now dangling images

    docker images -q --filter "dangling=true" | sudo xargs docker rmi
    
like image 43
Mutuma Avatar answered Oct 02 '22 08:10

Mutuma


Sincere appreciation to all of you. I have tried all your approaches, but was not able to delete the following image:

[myself@testvm]$ docker images -a
REPOSITORY    TAG     IMAGE ID      CREATED       SIZE
hello-world   latest  c54a2cc56cbb  6 months ago  1.848 kB

I had to remove it from here instead:

sudo rm /var/lib/docker/image/devicemapper/imagedb/content/sha256/c54a2cc56cbb2f04003c1cd4507e118af7c0d340fe7e2720f70976c4b75237dc 

Now it is gone.

like image 41
Ernest Schleicher Avatar answered Oct 02 '22 08:10

Ernest Schleicher


Running this cleanup script I made somehow magically solves this for me:

# remove orphan containers
docker ps -a | grep -v ":" | awk '{print $1}' | xargs docker rm -f

# remove orphan images
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi -f
like image 33
AlonL Avatar answered Oct 02 '22 08:10

AlonL


So... some cases of this seem to be because you have a no-longer-running container that references the image. Removing the container allows you to then remove the image.

But there is definitely a bug where docker gets itself into a state where no matter what you do, it can't remove any image. This has been fixed in docker 1.4.0: https://github.com/docker/docker/commit/ac40e7c

like image 35
David Röthlisberger Avatar answered Oct 02 '22 06:10

David Röthlisberger