簡體   English   中英

為什么摘要因注冊表而異?

[英]Why digests are different depend on registry?

AFAIK,圖像摘要是圖像清單正文的散列。

當我從 docker hub 拉出busybox鏡像,並將其推送到我的私有注冊表時,摘要變得不同。

$ docker pull busybox
...
Digest: sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4
Status: Downloaded newer image for busybox:latest

$ docker tag busybox myregistry/busybox
$ docker push myregistry/busybox
...
08c2295a7fa5: Pushed
latest: digest: sha256:8573b4a813d7b90ef3876c6bec33db1272c02f0f90c406b25a5f9729169548ac size: 527

$ docker images --digests
myregistry/busybox    latest      sha256:8573b4a813d7b90ef3876c6bec33db1272c02f0f90c406b25a5f9729169548ac   efe10ee6727f        2 weeks ago         1.13MB
busybox               latest      sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4   efe10ee6727f        2 weeks ago         1.13MB

圖像根本沒有改變,圖像 id 彼此相同。

但是為什么圖像摘要會有所不同呢?


更新:

有趣的是,來自另一個私有注冊表的摘要與我的私有注冊表的摘要完全相同。

$ docker image inspect efe10ee6727f
...
"RepoDigests": [
            "myregistry/busybox@sha256:8573b4a813d7b90ef3876c6bec33db1272c02f0f90c406b25a5f9729169548ac",
            "busybox@sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4",
            "anotherregistry/busybox@sha256:8573b4a813d7b90ef3876c6bec33db1272c02f0f90c406b25a5f9729169548ac"
        ],

您正在查看的摘要是注冊表摘要,它不同於圖像 ID 摘要。 您可以擁有一個映像 id,該映像 id 對它被推送的所有位置具有不同的注冊表引用(可能還有摘要)。 您可以在檢查輸出中看到兩個 ID:

$ docker inspect busybox --format 'Id: {{.Id}}
Repo Digest: {{index .RepoDigests 0}}'
Id: sha256:efe10ee6727fe52d2db2eb5045518fe98d8e31fdad1cbdd5e1f737018c349ebb
Repo Digest: busybox@sha256:2605a2c4875ce5eb27a9f7403263190cd1af31e48a2044d400320548356251c4

如果注冊中心使用舊的v1 manifest ,存儲庫名稱和標簽是該清單的一部分,這意味着它會隨着它在注冊中心之間移動而改變:

{
   "name": <name>,
   "tag": <tag>,
   "fsLayers": [
      {
         "blobSum": "<digest>"
      },
      ...
    ]
   ],
   "history": <v1 images>,
   "signature": <JWS>
}

然而,對於OCI manifestsDocker 的 v2 manifests ,情況不再如此,您應該看到相同圖像的相同注冊表摘要:

{
    "schemaVersion": 2,
    "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
    "config": {
        "mediaType": "application/vnd.docker.container.image.v1+json",
        "size": 7023,
        "digest": "sha256:b5b2b2c507a0944348e0303114d8d93aaaa081732b86451d9bce1f432a537bc7"
    },
    "layers": [
        {
            "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
            "size": 32654,
            "digest": "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f"
        },
        {
            "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
            "size": 16724,
            "digest": "sha256:3c3a4604a545cdc127456d94e421cd355bca5b528f4a9c1905b15da2eb4a4c6b"
        },
        {
            "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
            "size": 73109,
            "digest": "sha256:ec4b8955958665577945c89419d1af06b5f7636b4ac3da7f12184802ad867736"
        }
    ]
}

摘要本身是內容的 sha256 摘要,您也可以在OCI 的實現中找到。 當你在本地拉取一個鏡像時,一些事情會發生變化,包括被解壓縮的層,以及多平台鏡像被取消引用到你的本地平台。 由於這些更改,內容摘要將更改,圖像 ID 將與注冊表摘要不匹配。

因此,要在注冊中心之間比較圖像,請確保指定您想要帶有接受標頭的 v2 模式,否則注冊中心會將結果轉換回 v1 模式。 在 curl 中,傳遞這些標頭如下所示:

curl \
  -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
  -H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" \
  http://$registry/v2/$repo/manifests/$tag

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM