英文:
Why are docker container's filesystems smaller than their images?
问题
我是新手使用Docker,所以这可能看起来像一个愚蠢的问题,但我就是搞不明白。我已经了解到Docker镜像包含运行应用程序所需的压缩库和依赖项,而容器是从这些镜像创建的。
然而,我不明白的是,镜像中的这个压缩代码最终是如何在容器内执行的。在之前的研究中,我发现容器包含了此代码的副本,并且它们在此代码上添加了一个写入层以使其可运行。这就是为什么我觉得奇怪的是,实际上镜像的存储空间要比基于它们的容器的整个文件系统要大得多。你可能会期望,由于容器在其文件系统中有未压缩的代码,这些容器会比它们的镜像要大得多。
可能我完全误解了Docker的工作原理,但有人可以帮助我吗?提前谢谢!
英文:
I am new to using Docker, so this may seem like a silly question, but I just can't figure it out. I already learned that docker images contain the zipped libraries and dependencies needed to run the application, and that containers are created from these images.
However, what I don't understand is how this zipped code in the image is finally executed inside the container. In previous research I found that the containers contain copies of this code in their filesystem and that they add a write layer to this code in order to be runnable. That is why I find it strange to see that in practice images take much more storage than the entire filesystem of the containers based on them. You would expect that since the containers have the unzipped code in their filesystem, these containers would be much larger than their images.
Probably, I am completely misunderstanding how docker works, but can someone please help me? Thanks in advance!
答案1
得分: 2
容器不包含镜像文件系统的副本。
Docker基于所谓的覆盖文件系统,这是一种写时复制文件系统。
换句话说,您的容器开始使用合并的层文件系统(不再使用磁盘空间),然后对由运行容器更改的每个文件都写入一个新层,其大小等于更改文件的大小之和。
这里有关于这个概念的深入解释:
英文:
Containers don't contain copy of the image file system.
Docker is based on a so named overlay file system which is a copy-on-write file system.
In other words your container starts using merged layers file system (no more disk space is used), then for each file changed by the running container is written into a new layer, which is in size equal to the sum of the size of the changed files.
Here is in depth explanation of this concept:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论