Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
966 views
in Technique[技术] by (71.8m points)

how to tag image in docker registry v2

We have logic in our CI-CD that tags (via REST) staging image to latest (if tests are successful). This worked on registry v1.

We now moved to v2 api, and I can't find documentation on how to "add" tags to existing image in registry. I'm in a step that can bring the "manifest" of some staging image, but not sure how to add tag and POST it via http.

I tried to send the following inputs:

  1. "tag": "staging","latest",
  2. "tag": ["staging","latest"], and more
{
    "schemaVersion": 1,
    "name": "configservice",
    "tag": "staging",
    "architecture": "amd64",
    "fsLayers": [...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have Docker Registry that supports manifest schema version 2, you can just upload the manifest of an existing image under a new tag.

For example let's assume that you want to tag latest version of busybox image. The steps would be:

Download the existing manifest:

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

Here's what the manifest might look like (notice that schemaVersion is 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"
      }
   ]
}

Upload the manifest under a new tag:

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

Detailed step-by-step guide is give in this post.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...