且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当多个容器在同一主机上运行时,docker是否会重用映像?

更新时间:2023-11-22 19:15:28

Dockers 理解图像,容器和存储驱动程序详细说明了这一点.

Dockers Understand images, containers, and storage drivers details most of this.

从Docker 1.10开始,构成映像的所有层在构建时都具有与之关联的SHA256安全内容哈希.只要层的内容相同,此哈希在主机和内部版本之间就保持一致.

From Docker 1.10 onwards, all the layers that make up an image have an SHA256 secure content hash associated with them at build time. This hash is consistent across hosts and builds, as long as the content of the layer is the same.

如果任何数量的图像共享一个层,则该Docker引擎实例上的所有图像将仅存储和使用该层的1个副本.

If any number of images share a layer, only the 1 copy of that layer will be stored and used by all images on that instance of the Docker engine.

随着新版本的发布,像debian这样的标签可以随着时间引用多个SHA256图像哈希.仅当SHA256哈希匹配时,使用FROM debian构建的两个图像不一定共享图层.

A tag like debian can refer to multiple SHA256 image hash's over time as new releases come out. Two images that are built with FROM debian don't necessarily share layers, only if the SHA256 hash's match.

任何在其下运行Docker Engine的设备都将使用此存储设置.

Anything that runs the Docker Engine underneath will use this storage setup.

此共享也可在Docker Registry中使用(> 2.2可获得***效果).如果要推送具有该注册表上已存在的图层的图像,则将跳过现有图层.与将图层拖到本地引擎相同.

This sharing also works in the Docker Registry (>2.2 for the best results). If you were to push images with layers that already exist on that registry, the existing layers are skipped. Same with pulling layers to your local engine.