Docker如何计算每一层的哈希值?它是确定性的吗? [英] How Docker calculates the hash of each layer? Is it deterministic?

查看:176
本文介绍了Docker如何计算每一层的哈希值?它是确定性的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到有关Docker官方文档的信息,但没有成功.

I tried to find this information around the Docker official docs, but had no success.

Docker在计算每个提交/层的哈希值时会考虑哪些信息?

Which pieces of information does Docker take into account when calculating the hash of each commit/layer?

很明显,Dockerfile中的行是哈希的一部分,并且当然是父提交哈希.但是在计算此哈希值时是否还要考虑其他因素?

It's pretty obvious that the line in the Dockerfile is part of the hash and, of course, the parent commit hash. But is something else take into account when calculating this hash?

具体用例:假设我有两个开发人员在不同的机器上,并且在不同的时间点(因此,不同的docker守护程序和不同的缓存)在同一个Dockerfile上运行$ docker build .... FROM ...指令将为它们提供相同的起点,但是每个操作的结果散列是否会在相同的散列上产生?是确定性的吗?

Concrete use case: Let's suppose I have two devs in different machines, at different points in time (and because of that, different docker daemons and different caches) running $ docker build ... against the same Dockerfile. The FROM ... directive will give them the same starting point, but will the resulting hash of each operation result on the same hash? Is it deterministic?

推荐答案

感谢@thaJeztah.答案在 https://gist.github.com/aaronlehmann/b42a2eaf633fc949f93b# id定义和计算

Thanks @thaJeztah. Answer is in https://gist.github.com/aaronlehmann/b42a2eaf633fc949f93b#id-definitions-and-calculations

  1. layer.DiffID :单个图层的ID

计算:DiffID = SHA256hex(未压缩的图层tar数据)

Calculation: DiffID = SHA256hex(uncompressed layer tar data)

layer.ChainID :图层及其父级的ID.该ID唯一标识由一组图层组成的文件系统.

layer.ChainID: ID for a layer and its parents. This ID uniquely identifies a filesystem composed of a set of layers.

计算:

  • 对于底层:ChainID(layer0)= DiffID(layer0)
  • 对于其他层:ChainID(layerN)= SHA256hex(ChainID(layerN-1)+" + DiffID(layerN))

image.ID :图像的ID.由于映像配置引用了映像使用的层,因此此ID包含文件系统数据和其余映像配置.

image.ID: ID for an image. Since the image configuration references the layers the image uses, this ID incorporates the filesystem data and the rest of the image configuration.

计算:SHA256hex(imageConfigJSON)

Calculation: SHA256hex(imageConfigJSON)

这篇关于Docker如何计算每一层的哈希值?它是确定性的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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