W
W
wideShift2021-05-22 22:06:51
Docker
wideShift, 2021-05-22 22:06:51

If you delete the image that is used in the container, then why does the container not fall?

1) If the container is created based on the image, then why can't I delete the image? Why is this addiction? - You cannot delete an image (not forced) that is in use.
2) If you delete the image that is used in the container, then why does the container not fall?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-05-22
@wideShift

An image is not some set of files. This is essentially a list of layers (fslayer) that can be shared by different images. The image name (with tag) is a reference to the image id. An image can have multiple names (for example, foobar:1.2.3 and foobar:latest). Deleting an image by name does not delete the image, it only deletes the name, then if the image id no longer has other names and the image is no longer used by anyone, it deletes those fslayers of the image that are obviously not needed by other images and containers. So sometimes docker rmi just says "untagged image_name", and sometimes it actually removes some layers.

$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
540db60ca938: Pull complete 
Digest: sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
$ docker tag alpine foo/bar/lorem/ipsum:some.tag
$ docker rmi alpine
Untagged: alpine:latest
Untagged: [email protected]:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
$ docker rmi foo/bar/lorem/ipsum:some.tag
Untagged: foo/bar/lorem/ipsum:some.tag
Deleted: sha256:6dbb9cc54074106d46d4ccb330f2a40a682d49dda5f4844962b7dce9fe44aaec
Deleted: sha256:b2d5eeeaba3a22b9b8aa97261957974a6bd65274ebd43e1d81d0a7b8b752b116

When a container is created, a new layer is created on top of the layered image filesystem for the container's own files. Therefore, physically the image cannot be completely deleted as long as there is at least one container based on it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question