Frederico Oliveira
Frederico Oliveira

Reputation: 143

What happens to a docker container when I delete its image?

According to the docker documentation the relation between docker image and its respective containers is that the image contains the layers it used during its creation and a container from that image only adds another layer with its modifications. This is depicted bellow

With that in mind, I thought that deleting an image that has instantiated containers would invalidate them, since they would lose all the layers they depend upon. This theory is enforced by the error message you get when trying to delete an image thas has containers:

Error response from daemon: conflict: unable to delete dee20bb93b6a (must be forced) - image is being used by stopped container c44b4080aa76

But for my surprise when I forced the deletion of the image with -f flag and started the container, it just ran. Like that. No errors, no corruption, no missing files. No halt and catch fire. Nothing. It simply ran flawless from the exact state it was before having its image deleted.

My question is: what just happened? Why didn't the container become invalid?

Upvotes: 2

Views: 6841

Answers (1)

ideologic
ideologic

Reputation: 64

The container is an instantiated instance of the container image. As long as the previously created container exists and is not deleted, it does not have dependencies on the underlying container image.

Upvotes: 4

Related Questions