Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker image can't be deleted, "no such image"

Tags:

docker

Okay, so I'm brand new to Docker and doing some tutorials and I want to delete the nginx and mongo images:

$ docker image ls
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
nginx                latest              be1f31be9a87        12 days ago         109MB
mongo                3.4                 598e8cf490a6        12 days ago         361MB

So I start with nginx:

$ docker image rm nginx
Untagged: nginx:latest
Untagged: nginx@sha256:9ad0746d8f2ea6df3a17ba89eca40b48c47066dfab55a75e08e2b70fc80d929e
Deleted: sha256:be1f31be9a87cc4b8668e6f0fee4efd2b43e5d4f7734c75ac49432175aaa6ef9
Deleted: sha256:7609c40a03b852382a43d79231d9d4ca7661cd1ac9edcb46f78a44fff4ed59ca
Deleted: sha256:a2b6968c4326640dd5e9e22ddf6cebb61ba1a4b79a4ac8d194f93000c5a4c3e2
Deleted: sha256:8b15606a9e3e430cb7ba739fde2fbb3734a19f8a59a825ffa877f9be49059817

Has it gone?

$ docker image ls
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
mongo                3.4                 598e8cf490a6        12 days ago         361MB

So far so good. Now for mongo:

$ docker image rm mongo
Error: No such image: mongo

Why didn't this work?

In the end I found that docker image rm 598e8cf490a6 did remove the mongo image, but I still don't understand why this didn't work.

  • What is that first column, REPOSITORY? Is that the image name, or something else?
  • If it is the image name, then why can't I delete the mongo image using docker image rm mongo?
  • If it isn't the image name, then
    1. What is it?
    2. Why does docker image ls show it instead of the image name?
    3. How do I get the actual image name? And specifically what is it? I also tried docker image rm mongodb and docker image rm mongo-db with no success.
like image 259
qntm Avatar asked Oct 15 '18 11:10

qntm


People also ask

Why can’t I Delete my Docker image?

Oops! Docker is showing the error unable to delete the image (must be forced). We can help you fix it. Usually, this error shows up if a container is running in the image.

What is the difference between Docker image and Docker container?

Answer - Docker container is a runnable instance of Docker image. So if draw the tree hierarchy of Docker image and Docker container then Docker Image will sit at the top and Docker Container will sit underneath.

Why am I getting unable to delete the image (must be forced)?

Docker is showing the error unable to delete the image (must be forced). We can help you fix it. Usually, this error shows up if a container is running in the image.

Should I use Docker to keep a history of my images?

It's important to point out that you shouldn't use Docker to keep a history of your old images. For a developer environment that's fine, and you can even automate the image clean up workload if you have to deal with a lot of them. But for a production workload, you should be using a Container Registry solution to handle your Docker images.


1 Answers

As explained in the following thread - https://stackoverflow.com/a/23736802/10488199

An instance of an image is called a container. You have an image, which is a set of layers as you describe. If you start this image, you have a running container of this image. You can have many running containers of the same image. You can see all your images with docker images whereas you can see your running containers with docker ps (and you can see all containers with docker ps -a). So a running instance of an image is a container.

To view the list of running container instances

use -> $ docker ps

To view the list of all the container instances

use -> $ docker ps -a

To view, the list of images pulled

use -> $ docker images

To remove a container instance (if the container is running)

use -> $ docker kill <container id/container name> use -> $ docker rm <container id/container name>

or force it to stop and remove it by

use -> $ docker rm -f <container id/container name>

To remove a container instance (if the container is not running)

use -> $ docker rm <container id/container name>

To remove an image

use -> $ docker rmi <REPOSITORY:tag/IMAGEID>

or

use -> $ docker image rm <REPOSITORY:tag/IMAGEID>

NOTE: If the REPOSITORY being removed has the latest tag, there is no need of mentioning it. If there is a tag, it should be mentioned.

In your case

use -> $ docker images rm mongo:3.4

like image 58
armourshield Avatar answered Oct 11 '22 21:10

armourshield