user1689430
user1689430

Reputation: 77

What does remove container mean/do?

I am getting my hands dirty with Containers and Docker. In the world of Docker (or the world of Containers in general), I am trying to understand what "removing a container" means. The mental model I have of a container is that it is a running instance of an image. If a container has stopped executing, what resources is it consuming that need to be freed? I can understand removing the associated image(s) as they consume disk space. Maybe my mental model of a container as "a running instance of an image" is not correct, and there is more to it. If someone could shed some light, I would greatly appreciate it.

Upvotes: 5

Views: 2106

Answers (1)

Yogesh_D
Yogesh_D

Reputation: 18809

You are nearly there. In Docker when a container is run, the docker daemon mounts the images layers using a unionfs. It adds a layer on top of the images layers to track changes that are happening inside of that container. Say a log file is written that is tracked as part of this layer.

By removing a container you remove the resources use to track this layer of changes that the container has done on top of the image.

When a container is running it consumes CPU, memory and the HDD space associated with this layer.

When a container is stopped, the CPU and memory are released but the HDD space is still used. (You can check stopped containers using docker ps -a; this will show you all the containers across all states)

When a stopped container is removed the HDD space is also freed up. Docker also removes all the meta-data(when it was started, where its files are etc) associated with the container when you remove the container.

To have some more fun with this do this:

docker inspect <image_name>:<tag> and see its output.

docker inspect <containerid> and see its output, here containerid should be of a container running off the above image. And see if you can figure out the layers and cross relate them across the image and container.

Upvotes: 5

Related Questions