当多个容器在同一主机上运行时,docker是否会重用映像? [英] Does docker reuse images when multiple containers run on the same host?

查看:388
本文介绍了当多个容器在同一主机上运行时,docker是否会重用映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是Docker在dockerfile的每个阶段都创建了一个图像层.

My understanding is that Docker creates an image layer at every stage of a dockerfile.

如果我在同一台机器上运行X个容器(其中X> = 2),并且每个容器都有一个共同的基础映像层(即debian),则docker将在该机器上仅保留基础映像的一个副本,或者每个容器有多个副本吗?

If I have X containers running on the same machine (where X >=2) and every container has a common underlying image layer (ie. debian), will docker keep only one copy of the base image on that machine, or does it have multiple copies for each container?

是否有一个点可以分解,或者对dockerfile中的每一层都是正确的?

Is there a point this breaks down, or is it true for every layer in the dockerfile?

这是如何工作的?

Kubernetes会以任何方式影响这一点吗?

Does Kubernetes affect this in any way?

推荐答案

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.

这篇关于当多个容器在同一主机上运行时,docker是否会重用映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆