簡體   English   中英

如何在 docker registry v2 中標記圖像

[英]how to tag image in docker registry v2

我們的 CI-CD 中有邏輯標記(通過 REST)暫存圖像到latest (如果測試成功)。 這適用於注冊表 v1。

我們現在轉移到 v2 api,我找不到有關如何向注冊表中的現有圖像“添加”標簽的文檔。 我正處於可以帶來一些臨時圖像的“清單”的步驟中,但不確定如何添加標簽並通過 http 發布它。

我嘗試發送以下輸入:

  1. "tag": "staging","latest",
  2. "tag": ["staging","latest"],等等
{
    "schemaVersion": 1,
    "name": "configservice",
    "tag": "staging",
    "architecture": "amd64",
    "fsLayers": [...

如果您擁有支持清單模式版本 2 的 Docker Registry,您只需在新標簽下上傳現有圖像的清單。

例如,假設您要標記最新版本的busybox圖像。 步驟是:

下載現有清單:

curl '<registry_url>/v2/mybusybox/manifests/latest' \
-H 'accept: application/vnd.docker.distribution.manifest.v2+json' \
> manifest.json

下面是清單的樣子(注意 schemaVersion 是 2):

{
   "schemaVersion": 2,
   "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
   "config": {
      "mediaType": "application/octet-stream",
      "size": 1459,
      "digest": "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749"
   },
   "layers": [
      {
         "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
         "size": 667590,
         "digest": "sha256:8ddc19f16526912237dd8af81971d5e4dd0587907234be2b83e249518d5b673f"
      }
   ]
}

在新標簽下上傳清單:

curl -XPUT '<registry_url>/v2/mybusybox/manifests/new_tag' \
-H 'content-type: application/vnd.docker.distribution.manifest.v2+json' \
-d '@manifest.json'

這篇文章中提供了詳細的分步指南。

這不是對您問題的直接回答,但我一直在執行以下操作...

docker pull myimage:staging
docker run myimage:staging test  # this is optional
docker tag myimage:staging myimage:release
docker push myimage:release

請注意, docker pull將下載圖像,但如果注冊表中已經存在層,則docker push將不會再次上傳所有內容。

我只是想補充一下,因為這出現在我的搜索結果中,Google Container Registry 包含add-tag直接執行此操作add-tag命令

gcloud container images add-tag gcr.io/project/image:old-tag gcr.io/project/image:new-tag

上面 wheleph 描述的工作流程有效,但導致創建了一個新容器,而不是將附加標簽應用於現有容器。

此答案僅適用於更改圖像標簽,但我也想更改存儲庫名稱

感謝Nicholas Dille 的“如何在不拉取 docker 鏡像的情況下標記它們”的帖子,我也能夠更改repoName 他的nicholasdille/PowerShell-RegistryDocker項目項目的幫助下:

  1. 獲取清單(在 v2 模式中)
  2. 在新的 repo 中發布每個 layer.digest
  3. 后配置層
  4. 將整個清單放到新的倉庫中

詳情:

  1. reg:5000/v2/{oldRepo}/manifests/{oldtag}獲取清單,帶有accept標頭: application/vnd.docker.distribution.manifest.v2+json

  2. 對於每一層: POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={layer.digest}&from={oldRepoNameWithaoutTag}

  3. POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={config.digest}&from={oldRepoNameWithaoutTag}

  4. PUT reg:5000/v2/{newRepo}/manifests/{newTag} with content-type header: application/vnd.docker.distribution.manifest.v2+json and body from step 1 response

  5. 享受!

您可以使用docker buildx imagetools create實現此目的

docker buildx imagetools create myregistry.com/myimage:latest --tag myregistry.com/myimage:staging

這將簡單地下載myregistry.com/myimage:latest的圖像清單並將其重新標記(並推送)為myregistry.com/myimage:staging

PS這是我在這里的回答的轉貼

暫無
暫無

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

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