Reputation: 1063
When i try to delete an image via docker rmi
that has an existing container, i get an error message. ( normal )
When i add force flag docker rmi -f
the image is deleted and when i check containers state using docker ps -a
the container is still there but image namebecomes an ID.
So my question, from where comes this ID ? Is it a copy of the image that is kept in the cache and used for existing containers cause when i check docker images
i find an image with in repo and in name and its ID is the one that is newly affected to old existing containers.
Another question that follows : Once a container is created, is changing anything on the existing ( local ) image affecting in any way the existing containers ?
Thanks.
Upvotes: 2
Views: 2179
Reputation: 30723
A docker image has a name and an image ID. This blog describes where the image ID is comming from in pre-docker-v1.10 and after it.
If you perform docker rmi -f image of an image which is used by a running container you're actually not deleting the real image but deleting the name and tag on the image.
So indeed docker ps
will show:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
578e28246977 96931e4c66bd "/bin/tini -- /usr/lo" 3 minutes ago Up 3 minutes 8080/tcp, 50000/tcp drunk_shannon
But docker images
is still showing your image:
<none> <none> 96931e4c66bd 6 weeks ago 711.9 MB
It's just untagged. The image isn't also deleted after you delete this container. The image remains in the list. You can start new containers from it with docker run -d 96931e4c66bd
(by using the ID)
You can even retag it:
docker tag 96931e4c66bd my-jenkins:1.0
Than docker images
shows:
my-jenkins 1.0 96931e4c66bd 6 weeks ago 711.9 MB
Another question that follows : Once a container is created, is changing anything on the existing ( local ) image affecting in any way the existing containers ?
No, when you make an "update" on your image (same name), the running container will probably lose it's image-name (only has an ID, just like when you're deleting your image during the container is running). You'll need to reexecute the run-command with the new image (which will have another image-ID after the update) to have a container running from the newest image.
Upvotes: 3