How Docker calculates the hash of each layer? Is it deterministic?

前端 未结 1 488
再見小時候
再見小時候 2021-02-18 21:49

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

Which pieces of information does Docker take into account when calculating the hash

相关标签:
1条回答
  • 2021-02-18 21:54

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

    1. layer.DiffID: ID for an individual layer

      Calculation: DiffID = SHA256hex(uncompressed layer tar data)

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

      Calculation:

      • For bottom layer: ChainID(layer0) = DiffID(layer0)
      • For other layers: ChainID(layerN) = SHA256hex(ChainID(layerN-1) + " " + DiffID(layerN))
    3. 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.

      Calculation: SHA256hex(imageConfigJSON)

    0 讨论(0)
提交回复
热议问题