Docker 注册表 space 如果从同一个 docker 文件推送两个图像

Docker registry space if pushing two images from same docker file

当从同一个 docker 文件创建映像时,docker 注册表服务器 space 端会发生什么。因此,例如在下面的情况下,如果我推送带有标签 1.0 的图像,然后使用相同的 docker 文件创建另一个图像并使用标签 1.1 推送该图像。 docker 注册表是否需要额外的 space?

docker build . -t myRegistry.com/myImage:1.0
docker push myRegistry.com/myImage:1.0

docker build . -t myRegistry.com/myImage:1.1
docker push myRegistry.com/myImage:1.1

docker build . -t myRegistry.com/myImage:1.2
docker push myRegistry.com/myImage:1.2

docker build . -t myRegistry.com/myImage:1.3
docker push myRegistry.com/myImage:1.3

在您的示例中,容器注册表将使用相同的图像,该图像由图像的 sha256 值(也称为 IMAGE ID)计算得出——标签只是该唯一图像的别名。

这是一种 one-to-many 关系,也就是说,您可以让多个标签指向同一张图片。您可以使用 docker images --no-trunc 查看图像 ID 的完整值。 (请注意,如果您在使用 "latest" 或 "develop" 等常见标签时遇到一致性问题,这很有用,因为除非您使用 sha256 值,否则您无法确定它实际上是哪个图像。)

对于基于不同 machines/environments 的构建,使用具有相同文件的相同 Dockerfile 可能 会产生相同的散列,但它 depends on many variables 就像动态一样您的依赖项是,如果时间戳已更改等

正如@Henry 所提到的,这进一步适用于(主要在幕后)图像的各个层:

Docker images have intermediate layers that increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached. These intermediate layers are not shown by default.

see docs

顺便说一句,要查看 容器 的 sha256 值以查看它来自哪个 image,您可以 inspect它,例如 docker inspect --format='{{index .RepoDigests 0}}' mongo:3.4-jessie