当您从 Docker 注册表中提取多架构清单时,它会自动选择与您的计算机架构相匹配的单个映像并提取该映像(如果可能);从客户端来看,这看起来与拉取单架构图像清单相同。有没有办法从客户端确定清单是单架构还是多架构,例如通过查询 API 端点?
是的,有很多工具可以实现这一点。 docker 内置的是:
$ docker buildx imagetools inspect busybox
Name: docker.io/library/busybox:latest
MediaType: application/vnd.docker.distribution.manifest.list.v2+json
Digest: sha256:7b3ccabffc97de872a30dfd234fd972a66d247c8cfc69b0550f276481852627c
...
您正在寻找媒体类型。
application/vnd.docker.distribution.manifest.list.v2+json
和 application/vnd.oci.image.index.v1+json
是多平台清单,包含支持的平台列表。
除了docker之外,还有Google的crane、RedHat的skopeo、我自己的regclient/regctl。使用 regctl 给出真/假的 shell 脚本示例可以通过格式化输出来完成:
$ regctl manifest get busybox --format '{{ .IsList }}'
true
$ regctl manifest get busybox --platform local --format '{{ .IsList }}'
false
要仅获取
MediaType
值,您可以运行:
$ docker buildx imagetools inspect --format '{{json .Manifest.MediaType}}' busybox
"application/vnd.oci.image.index.v1+json"