Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are container's size and image's size equivalent?

Tags:

docker

The glossary of docker says that

A Docker container consists of

  • A Docker image

  • Execution environment

  • A standard set of instructions

When I type docker images, I see 324.2 MB in SIZE column of mysql:5.6.

When I type docker ps -s -a, this command tells me that the size of the container, which is created by docker run mysql:5.6 -d, is also 324.2 MB.

Does this mean that Execution environment and A standard set of instructions do not occupy any disk space?

or the disk space they use is less than 0.1 MB?

or docker ps -s -a just lists the size of the container's image?

like image 472
Brian Avatar asked Mar 13 '23 19:03

Brian


1 Answers

Because of the copy-on-write mechanism, the size of a container is... at first 0.

Meaning, you can launch 100 containers, then won't take 100 times the size of the image. They will share the filesystem proposed by the image.
Then any modification done during the life of the container will be written in a new layer, one per image.

See more at "Understand images, containers, and storage drivers":

When you create a new container, you add a new, thin, writable layer on top of the underlying stack. This layer is often called the “container layer”.

All changes made to the running container - such as writing new files, modifying existing files, and deleting files - are written to this thin writable container layer. The diagram below shows a container based on the Ubuntu 15.04 image.

https://docs.docker.com/engine/userguide/storagedriver/images/container-layers.jpg

like image 198
VonC Avatar answered Apr 29 '23 00:04

VonC