如何通过Docker REST API查找与latest标签同义的镜像标签及按摘要分组获取对应标签
Great questions! Let's break this down step by step for you:
To locate other tags that point to the same image as the "latest" tag, follow these two core steps:
Step 1: Retrieve the digest of the "latest" image
First, fetch the manifest for the "latest" tag to get its unique image digest. Use this API call:GET /v2/<your-repo>/<your-image>/manifests/latestBe sure to set the
Acceptheader toapplication/vnd.docker.distribution.manifest.v2+json(this ensures you receive the modern v2 manifest format). The critical detail here is the Docker-Content-Digest header in the response—this is the unique identifier for the image that "latest" references.Step 2: Match other tags to this digest
There’s no single API call that directly maps tags to their digests, so you’ll need to:- Fetch all tags for the image with:
GET /v2/<your-repo>/<your-image>/tags/list - For each tag in the returned list, send a
HEADrequest to retrieve its digest:HEAD /v2/<your-repo>/<your-image>/manifests/<tag> - Compare the Docker-Content-Digest header from each
HEADresponse to the digest you obtained for "latest". Any tags with a matching digest are synonymous with "latest".
- Fetch all tags for the image with:
You’re correct that the /tags/list endpoint only returns a flat list of tags—there’s no built-in API endpoint that groups tags by their underlying image digest. Here’s how to solve your specific scenario:
First, get the digest for the "latest" tag
Use thisGETrequest for your private repository:GET /v2/myrepository/troubleshooting/manifests/latestCapture the Docker-Content-Digest header value (let’s refer to this as
TARGET_DIGEST).Fetch all tags for the "troubleshooting" image
Call:GET /v2/myrepository/troubleshooting/tags/listThis will return all 5 tags associated with your image versions.
Filter tags by the target digest
Loop through each tag from the list, and for each one, send aHEADrequest:HEAD /v2/myrepository/troubleshooting/manifests/<tag>Check if the Docker-Content-Digest header matches
TARGET_DIGEST. Collect all tags that match—these are the other tags linked to the same latest version image.
A quick efficiency note
If you need to group all 5 image versions by their digests (not just the latest), you can build a dictionary where keys are digests and values are lists of associated tags. Simply process every tag’s digest and populate the dictionary accordingly.
内容的提问来源于stack exchange,提问作者Vaccano

