How to tag an image in the docker registry v2

Our CI-CD has logic in which tags (via REST) ​​put the image in the past (if the tests are successful). This worked in the v1 registry.

Now I’ve moved to v2 api, and I can’t find in the documentation how to “add” tags to an existing image in the registry. I am taking a step that can bring a “manifest” of some intermediate image, but not sure how to add a tag and http-post it. tried to send the input below

  • "tag": "staging", "latest",

  • "tag": ["staging", "latest"], and more

    {"schemaVersion": 1, "name": "configservice", "tag": "staging", "architecture": "amd64", "fsLayers": [....

+14
source share
3 answers

If you have a Docker Registry that supports manifest scheme 2, you can simply load the manifest of the existing image under the new tag.

For example, suppose you want to tag the latest version of a busybox image. Stages:

Download existing manifest:

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

The manifest will look here (note 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" } ] } 

Download the manifest under the new tag:

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

A detailed walkthrough is given in post .

+11
source

This is not a direct answer to your question, but I always did the following ...

 docker pull myimage:staging docker run myimage:staging test docker tag myimage:staging myimage:release docker push myimage:release 
+7
source

I just wanted to add, as it appeared in my search results, that the Google container registry includes a command to do this directly.

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

The workflow described above worked, but led to the creation of a new container, rather than adding an additional tag to the existing one.

0
source

Source: https://habr.com/ru/post/989847/


All Articles