You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Docker REST API查找与latest标签同义的镜像标签及按摘要分组获取对应标签

Great questions! Let's break this down step by step for you:

1. Finding tags synonymous with "latest" via Docker REST API

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/latest
    

    Be sure to set the Accept header to application/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:

    1. Fetch all tags for the image with:
      GET /v2/<your-repo>/<your-image>/tags/list
      
    2. For each tag in the returned list, send a HEAD request to retrieve its digest:
      HEAD /v2/<your-repo>/<your-image>/manifests/<tag>
      
    3. Compare the Docker-Content-Digest header from each HEAD response to the digest you obtained for "latest". Any tags with a matching digest are synonymous with "latest".
2. Grouping tags by image digest for your private "troubleshooting" image

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:

  1. First, get the digest for the "latest" tag
    Use this GET request for your private repository:

    GET /v2/myrepository/troubleshooting/manifests/latest
    

    Capture the Docker-Content-Digest header value (let’s refer to this as TARGET_DIGEST).

  2. Fetch all tags for the "troubleshooting" image
    Call:

    GET /v2/myrepository/troubleshooting/tags/list
    

    This will return all 5 tags associated with your image versions.

  3. Filter tags by the target digest
    Loop through each tag from the list, and for each one, send a HEAD request:

    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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 18:57:40