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.
REPOSITORY
? Is that the image name, or something else?mongo
image using docker image rm mongo
?docker image ls
show it instead of the image name?docker image rm mongodb
and docker image rm mongo-db
with no success.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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With