Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the size and the virtual size of the docker images?

I have a private registry where I store all of my docker images.

I noticed that when I pull an image from it,the difference in the sizes of the image on my local machine and the one on the registry is significant.

For example,I have an image called mydb (around 126 MB).

When I pull it on my local machine and execute "docker images", it says that the "VIRTUAL SIZE" of that image is now almost three times larger (388 MB).

I was wondering what is the the reason for it and what "VIRTUAL SIZE" actually means.

Thank you :) .

like image 223
Ilian Velchev Avatar asked Jun 22 '16 11:06

Ilian Velchev


People also ask

What is the virtual size of a Docker image?

Back to the docker ps -s output; The "size" information shows the amount of data (on disk) that is used for the writable layer of each container The "virtual size" is the total amount of disk-space used for the read-only image data used by the container and the writable layer.

What is difference between Docker container and VM?

Docker containers are considered suitable to run multiple applications over a single OS kernel; whereas, virtual machines are needed if the applications or services required to run on different OS.

What is Docker image size?

On the Docker Hub website the base image is listed as 29 MB. When the child image is built it downloads and installs Python, making it grow larger. Besides using Alpine base images, another method for reducing the size of your images is using multistage builds.

What is the difference between virtual environment and Docker?

Docker vs VM: ArchitectureA virtual machine requires multiple or different kernels to run applications across servers. But, with Docker, a single operating system kernel is effectively used to run multiple applications across all containers.


1 Answers

You can find a good explanation of this concept here: https://github.com/docker/docker.github.io/issues/1520#issuecomment-305179362

From thaJeztah

The "size" and "virtual size" describe the amount of disk space used by a container. Let me try and explain:

When starting a container, the image that the container is started from is mounted read-only. On top of that, a writable layer is mounted, in which any changes made to the container are written.

The read-only layers of an image can be shared between any container that is started from the same image, whereas the "writable" layer is unique per container (because: you don't want changes made in container "a" to appear in container "b" smile)

Back to the docker ps -s output;

The "size" information shows the amount of data (on disk) that is used for the writable layer of each container The "virtual size" is the total amount of disk-space used for the read-only image data used by the container and the writable layer. The reason it's named "virtual size", is that (as described earlier), the disk space for the read-only layer(s) can be shared between containers, so only take up disk space once (perhaps a different name ("shared" size?) would have been better in hindsight, but naming is hard :) ). edit: virtual actually shows the combined size of the readonly layer (the image), and the writable layer of the container.

In the example below, I started 10 nginx containers;

enter image description here

All these containers use the same image, so the "Virtual size" (183MB in the example) is used only once, irregardless of how many containers are started from the same image - I can start 1 container or a thousand; no extra disk space is used. The "Size" (2B in the example) is unique per container though, so the total space used on disk is:

183MB + 10 * 2B

Be aware that the size shown does not include all disk space used for a container. Things that are not included currently are;

  • disk space used for log-files (if you use the json-file logging driver) - which can be quite a bit if your container generates a lot of logs, and log-rotation (max-file / max-size logging options) is not configured
  • volumes used by the container
  • disk space used for the container's configuration files (hostconfig.json, config.v2.json, hosts, hostname, resolv.conf) -
    although these files are small
  • memory written to disk (if swapping is enabled)
  • checkpoints (if you're using the experimental checkpoint/restore feature)
like image 85
Geige V Avatar answered Oct 23 '22 17:10

Geige V