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

如何从Docker Registry REST API获取schemaVersion 2的镜像清单?

获取Docker Registry的schemaVersion 2镜像清单

你之前用错了请求头——GET请求中应该用Accept头指定期望的响应类型,而非Content-Type。Content-Type是用来告诉服务器你发送的请求体格式,GET请求通常没有请求体,所以这个头不会生效。

解决步骤:

  • 发送GET请求时,在请求头中添加Accept,值设为你需要的v2清单媒体类型:
    • 单架构镜像用:application/vnd.docker.distribution.manifest.v2+json
    • 多架构镜像(manifest list)用:application/vnd.docker.distribution.manifest.list.v2+json
    • 也可以同时指定多个类型,用逗号分隔,让服务器返回最匹配的版本:application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json

Python请求示例:

import requests

registry_url = "http://docker.lan:5000/v2/my-image/manifests/latest"
headers = {
    "Accept": "application/vnd.docker.distribution.manifest.v2+json"
}

resp = requests.get(registry_url, headers=headers)
resp.raise_for_status()  # 处理请求错误
manifest = resp.json()

# 计算未压缩总大小:累加所有layer的size字段
uncompressed_size = sum(layer["size"] for layer in manifest["layers"])
print(f"未压缩总大小:{uncompressed_size} bytes")

如果请求后仍然返回v1清单,需要检查:

  1. 目标镜像是否真的存在schemaVersion 2的清单(有些旧镜像可能只有v1)
  2. 确认Registry配置是否启用了v2支持(官方最新版默认支持,无需额外配置)

内容的提问来源于stack exchange,提问作者DasMoorhuhn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 18:12:09