docker: Error: failed to remove one or more images - docker

I am not able to remove this image docker run -p 8080:80 bgruening/galaxy-stable
$ sudo docker ps -a -q
69a86acd37be
87540cb4904e
5c3e20ad2159
1426b69a9709
2cba8dcddd66
52b492693f21
$ sudo docker rmi 52b492693f21
Error response from daemon: No such image: 52b492693f21
FATA[0000] Error: failed to remove one or more images
How can I remove this image?
Thank you in advance.

You are listing the containers and trying to remove a container. Use docker images to list all the images and remove it with docker rmi IMAGEID with the proper id. If your intention is remove a container, not an image, use docker rm CONTAINERID

run the wrong command to list docker images, it should be:
docker images
then you should be fine to remove the images with docker rmi
But before to do that, make sure, the related containers all cleaned already.
docker ps -a
docker rm -f XXXXXX # -f means force removed if some of them are still in run mode.

In your case, I think that you want to stop and remove a container after you run it docker run -p 8080:80 bgruening/galaxy-stable
So you should run 2 commands below:
sudo docker stop 52b492693f21
sudo docker rm 52b492693f21
If you need to remove a image, you should use commands docker images to list all images, and docker rmi to remove a image.
Hope it helps

Related

Difference between docker rm IMAGE vs docker rmi IMAGE

According to Docker documentations, docker image rm "Remove one or more images" [1]. docker rmi has a same description [2], but then it goes on to say "Removes (and un-tags) one or more images from the host node."
Do docker image rm IMAGE and docker rmi IMAGE have an identical effect under any scenario? IMAGE is ID of the particular image that is to be removed.
The man page for docker rmi specifies that docker rmi is an alias for docker image rm. I suppose the documentation from docker is a little bit inconsistent in that regard. They write all the details for docker rmi while the documentation for docker image rm is lackluster.
It looks like docker rm is for containers and docker rmi is for images.
PS C:\Users\3des> docker rm httpd --force
Error: No such container: httpd
PS C:\Users\3des> docker rm httpd
Error: No such container: httpd
______________________________________________
PS C:\Users\3des> docker rmi httpd --force
Untagged: httpd:latest
Untagged: httpd#sha256:2fab99fb3b1c7ddfa99d7dc55de8dad0a62dbe3e7c605d78ecbdf2c6c49fd636
``
1). The docker image rm command "Remove one or more containers" not container image.
to check for container and its ID "docker ps -a" command
2). However, the docker rmi command means rm = remove i = image.
it is used to removing docker images. remembers that containers are created from images.
the "docker images or docker image ls" shows images, repository, TAG, and image ID.
docker rmi <image_ID> to remove image.
NOTE even when it is possible to create a new image from the existing image using the "docker commit" command, such image will come it its unique image id.

Docker: Error response from daemon: remove myvol: volume is in use

When I'm trying to remove a volume I get this error:
Error response from daemon: remove myvol: volume is in use -
[2a177cb40a405db9f245fccd776dcdeacc d266ad624daf7cff510c9a1a1716fe]
But both docker ps and docker container ls return an empty list.
I've tried restarting the docker daemon.
I use Docker Toolbox on Windows 10.
try to delete all stopped containers:
docker rm -f $(docker ps -a -q)
then delete the volume
you can see stopped container using docker ps -a using docker ps will return only running containers
EDIT since you are on Windows
list stopped containers:
docker ps -a
delete the stopped container - you need to replace CONATINER_ID with your real ones -:
docker rm -f CONATINER_ID_1 CONATAINER_ID_2
To fix this error, you need to remove the container [2a177cb40a405db9f245fccd776dcdeacc d266ad624daf7cff510c9a1a1716fe] before removing the volume.
You can use this ID to remove the container:
$ docker rm 2a177cb40a405db9f245fccd776dcdeacc d266ad624daf7cff510c9a1a1716fe
Note: Removing the container will not affect the volume. The ls command will still list this volume.
$ docker volume ls
After you removed the container, the volume is now free for deletion. so you can use the rm command to delete the Docker volume “[Volume Name]”:
$ docker volume rm [Volume Name]

Docker rmi - Is it okay to use --force?

I am rather new to Docker, I have recently started running ubuntu container, and stopped it gracefully a few days later (I do not see it using "docker ps"). When I tried to remove ubuntu image using
docker rmi ubuntu
I got the following error:
Error response from daemon: conflict: unable to remove repository reference "ubuntu" (must force) - container 65c315b169b8 is using its referenced image 747cb2d
60bbe
Can I use "--force" to force a removal of the image,
docker rmi ubuntu --force
Or is there a graceful/safer way to do it?
By default docker ps will only show running containers. You can show the stopped ones using docker ps --all.
You can then remove the container first with docker rm <CONTAINER_ID>
If you want to remove all of the containers, stopped or not, you can achieve this from a bash prompt with
$ docker rm $(docker ps --all -q)
The -q switch returns only the IDs
Since everyone else seemed unwilling to test yet willing to preach, I decided to test this out myself:
I downloaded a new image so I knew it wasn't in use
I ran a new container
I deleted the image using docker rmi --force <name>
Image was only untagged, not deleted
I failed to delete the image using docker rmi --force <ID> as docker rebuked with "image is being used by running container 922a12161de6"
So the results are:
The image gets untagged when you name it, but Docker (at least the version I'm using, 19.03.5 build 633a0ea) is smart enough to not actually delete the layers when they are in use.
As a result, the container continues to run fine as the layers are still there, they're simply untagged. You can docker rmi <ID> or docker images prune (without -a it will only delete "dangling" images, I. E. not including unused ones).
Thus the answer is "yes, but it won't delete containers if that's what you're hoping for", but now you know why.
I'm not satisfied with how most of the other answers tell you to find running containers, however, since they seem to say "list all images" -- why? You're trying to delete a specific image.
Stefano's answer is more accurate but here are some tweaks to it:
imageName=ubuntu
containerIds=$(docker ps -a | grep "$imageName" | awk '{ print $1 }')
docker stop $containerIds
docker rm $containerIds
docker rmi "$imageName"
Basically, I added a variable for the image naem and a stop step.
Docker doesn't copy the image data to each container, all the containers running the image have a read only pointer to that part of the filesystem (with their own local RW layer for the individual containers). So if you delete an image while a container is using it, you would break the container and overlay filesystem that it depends on.
Instead, just remove the container first. It may be exited rather than running, so you can do a docker ps -a | grep $image_id for a quick list of containers running that specific image id, but the preferred list would include any descendants:
docker rm $(docker ps -aq --filter "ancestor=747cb2d60bbe")
Then you'll be able to run your docker image rm (or docker rmi) command.
Update: If you force remove an image, all docker does is untag it. The image layers still exists on the filesystem until the container is deleted and then you can delete those image layers. E.g.:
/ $ docker run -d --rm busybox tail -f /dev/null
dac68c445371feab453ba3e3fc80efee52043f6b177fd0a71d0b55b38753f2cf
/ $ docker image rm busybox
Error response from daemon: conflict: unable to remove repository reference "busybox" (must force) - container dac68c445371 is using its referenced image 020584afccce
/ $ docker image rm --force busybox
Untagged: busybox:latest
Untagged: busybox#sha256:1303dbf110c57f3edf68d9f5a16c082ec06c4cf7604831669faf2c712260b5a0
/ $ docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 020584afccce 2 weeks ago 1.22MB
Even after deleting the container the layers are still there:
/ $ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dac68c445371 020584afccce "tail -f /dev/null" 52 seconds ago Up 50 seconds brave_yalow
/ $ docker stop dac
dac
/ $ docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 020584afccce 2 weeks ago 1.22MB
But after the container has been removed you can cleanup the layers:
/ $ docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Deleted Images:
deleted: sha256:020584afccce44678ec82676db80f68d50ea5c766b6e9d9601f7b5fc86dfb96d
deleted: sha256:1da8e4c8d30765bea127dc2f11a17bc723b59480f4ab5292edb00eb8eb1d96b1
Total reclaimed space: 1.22MB
If you want to do it gracefully, you should find if there are other images using ubuntu. Anyway in your case, you have a container related to that image.
Here's an example script on how to get this:
containerId=$( docker container ls -a | grep ubuntu | awk '{ print $1 }' )
docker container rm $containerId
docker image rm ubuntu
Remove all containers and after all images to win some space !
$ docker rm $(docker ps -all -q)
$ docker rmi $(docker image ls -q)
You can try the prune option available with docker images in case you want to remove all unused images.
https://docs.docker.com/engine/reference/commandline/image_prune/#usage
docker image prune -a
When would one delete docker images
When they are short of disk space and
They know for certain that they dont need an image or if they can readily download from internet/docker registry later when they need
So if you have internet access and if you have disk space issues you can just delete the image by force
Why you are getting the error:
Docker thinks there is a container - which is currently stopped - which was using this image. If you delete this stopped docker, "docker rmi" would work without force
These are the basic useful commands for docker to view and delete stuff.
View all docker images: docker image ls
View docker containers: docker ps
Stop docker container: docker stop <container name>
Remove docker container: docker rm <container name>
Remove docker image: docker rmi image <image name>
Delete Docker images except for current one - docker image prune -a

Cant delete Docker image

I want to delete a image but i get
Failed to remove image (b9387432d394): Error response from daemon:
conflict: unable to delete b9387432d394 (cannot be forced) - image has
dependent child images
I have done this a few times but never run into a problem like this.
Ive run a image (doesnt really care what it was)
$ docker run -dt ubuntu:16.04
Ive logged in and created a empty file
$ docker exec -it <my_container_id>
Ive logged out and create a new image with the commit command
$ exit
$ docker commit -m "some change" <container_id> <new_image_name>
Ive removed all containers
$ docker rm $(docker ps -a -q)
Ive verified that all containers are gone and my image is in the list
$ docker ps
// received a empty list
$ docker images
// received a list with the base and my new image
Ive tried to remove the base image
$ docker rmi -f <image_id>
But i received the error Failed to remove image
You can remove the untagged images using
docker rmi $(docker images -aq -f dangling=true)

docker cannot remove images?

docker images
lists
test latest e10eb3d3a067 7 days ago 1.094 GB
But i tried to remove it using
docker rmi e10eb3d3a067
docker rmi -f <same_id>
It says, No such id :<different id, not the one i provided> and Error: failed to remove
Any suggestions to remove it?
I reffered this But i don't have any running contianers and no dependency between images that i want to remove.
Use the below command to list down all the containers
docker ps -a --format="container:{{.ID}} image:{{.Image}}"
Try to remove the image which you want
sudo docker rmi <image-id>
If you still get the same error then try to remove the containers associated with that image.
sudo docker rm <container-id>
Now try to remove the image

Resources