简体   繁体   中英

Find docker tags that are synonyms of the "latest" tag via the REST API

I have a container image called troubleshooting . There are 5 different versions of the image in the my private repository. (Meaning 5 different image digests listed.)

The most recent image has a tag on it called latest . I need a way to get the other tags on that same image. I am doing this in a build script, so I would prefer to keep it through the REST API that docker has.

I tried used the /v2/myrepository/myimage/tags/list endpoint, but it lists all the tags without breaking them up by digest.

Is there a way to get tags broken up by digest? (Using the REST API?)

At present, you would need to perform a HEAD request on each tag, with the proper accept headers, to get the digest. There are suggestions to extend OCI's distribution-spec with a better tag API, but that will take some time to get approved and then implemented by the various registries.

Here's an example script for querying Docker Hub for either a docker manifest or manifest list (there are additional media types available for things like OCI image/index):

#!/bin/sh

ref="${1:-library/ubuntu:latest}"
sha="${ref#*@}"
if [ "$sha" = "$ref" ]; then
  sha=""
fi
wosha="${ref%%@*}"
repo="${wosha%:*}"
tag="${wosha##*:}"
if [ "$tag" = "$wosha" ]; then
  tag="latest"
fi
api="application/vnd.docker.distribution.manifest.v2+json"
apil="application/vnd.docker.distribution.manifest.list.v2+json"
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
        | jq -r '.token')
curl -H "Accept: ${api}" -H "Accept: ${apil}" \
     -H "Authorization: Bearer $token" \
     -I -s "https://registry-1.docker.io/v2/${repo}/manifests/${sha:-$tag}"

And the resulting headers that includes the docker-content-digest field:

$ ./manifest-v2-head.sh
HTTP/1.1 200 OK
content-length: 1416
content-type: application/vnd.docker.distribution.manifest.list.v2+json
docker-content-digest: sha256:a0d9e826ab87bd665cfc640598a871b748b4b70a01a4f3d174d4fb02adad07a9
docker-distribution-api-version: registry/2.0
etag: "sha256:a0d9e826ab87bd665cfc640598a871b748b4b70a01a4f3d174d4fb02adad07a9"
date: Fri, 08 Oct 2021 18:04:26 GMT
strict-transport-security: max-age=31536000
ratelimit-limit: 100;w=21600
ratelimit-remaining: 100;w=21600
docker-ratelimit-source: 68.100.24.47

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM