skip to Main Content

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:

enter image description here

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


  1. When Docker says that 2db29710123e: Already exists, yes, it already exists on your local machine. It doesn’t exist as part of the hello-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 running docker image rm hello-world:

    Error response from daemon: conflict: unable to remove repository reference "hello-world" (must force) – container 4d198a310ed5 is using its referenced image feb5d9fea6a5

    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 or docker 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.

    Login or Signup to reply.
  2. You have to first stop and remove the docker container using the image using below code:

    docker kill <container-id> # kills the container
    
    docker rm <container-id> # remove container using hello-world image
    

    Then, finally you can remove the image.

    docker image rm hello-world  # remove the hello-world image
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search