gpt4 book ai didi

docker - docker 镜像的大小和虚拟大小有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 21:24:12 26 4
gpt4 key购买 nike

我有一个私有(private)注册表,用于存储我的所有 docker 镜像。

我注意到,当我从中提取图像时,本地计算机上的图像大小与注册表上的图像大小差异很大。

例如,我有一个名为 mydb(大约 126 MB)的图像。

当我将它拉到我的本地机器上并执行 "docker images" 时,它会显示该图像的 "VIRTUAL SIZE"现在几乎是原来的三倍 (388 MB)。

我想知道这是什么原因以及“虚拟尺寸”的实际含义。

谢谢你:)。

最佳答案

你可以在这里找到对这个概念的一个很好的解释:https://github.com/docker/docker.github.io/issues/1520#issuecomment-305179362

来自 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)

关于docker - docker 镜像的大小和虚拟大小有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37966973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com