Just in the process of learning Docker. Tried to run the hello-world example:
# docker run hello-world
Worked.
Removed the image using
# docker image rm -f <image-id>
Worked.
# docker images
Shows no images.
Now, if I try to run the hello-world example again, it shows this:
It mentions:
2db29710123e: Already exists
Does this mean, the image already exists on the local host machine, or the image does exist on the Docker Registry, and this is a new pull?
Any insight would be much appreciated.
2
Answers
When Docker says that
2db29710123e: Already exists
, yes, it already exists on your local machine. It doesn’t exist as part of thehello-world
image though, because you force-removed that beforehand. However, why did you have to force-remove it in the first place? Why wasn’t a regular remove enough? Here is the message it shows, when runningdocker image rm hello-world
:This means you still have a container (from the previous hello-world test) which references that image. So when you force-remove, the image (tag or label) is removed from
docker images
, but the underlying data is still there, locally, because of the existing container.However, if you remove the container (with
docker container rm
ordocker container prune
for example) before running the hello-world test again, you will pull the image from the repository, because it doesn’t exist locally anymore. And if you remove the container before removing the image, you won’t need the force-remove anymore, either.You have to first stop and remove the docker container using the image using below code:
Then, finally you can remove the image.