# docker registry v2 API 的理解与一些验证

发布于:2023-01-04 ⋅ 阅读:(386) ⋅ 点赞:(0)

API官方文档:https://docs.docker.com/registry/spec/api/

API官方文档翻译:https://docs.docker.com.zh.xy2401.com/registry/spec/api/

1 API methods and URIs :

Method Path Entity Description
GET /v2/ Base Check that the endpoint implements Docker Registry API V2.
GET /v2/<name>/tags/list Tags Fetch the tags under the repository identified by name.某仓库下的tag列表
GET /v2/<name>/manifests/<reference> Manifest Fetch the manifest identified by name and reference where reference can be a tag or digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.获取某仓库某tag信息清单,带上请求header,可以获得指定信息,而不是全部
PUT /v2/<name>/manifests/<reference> Manifest Put the manifest identified by name and reference where reference can be a tag or digest.
DELETE /v2/<name>/manifests/<reference> Manifest Delete the manifest identified by name and reference. Note that a manifest can only be deleted by digest.镜像摘要
GET /v2/<name>/blobs/<digest> Blob Retrieve the blob from the registry identified by digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data.
DELETE /v2/<name>/blobs/<digest> Blob Delete the blob identified by name and digest实践得知:这个digest就是镜像ID那个,与manifests的digest不是同一个
POST /v2/<name>/blobs/uploads/ Initiate Blob Upload Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the digest parameter is present, the request body will be used to complete the upload in a single request.
GET /v2/<name>/blobs/uploads/<uuid> Blob Upload Retrieve status of upload identified by uuid. The primary purpose of this endpoint is to resolve the current status of a resumable upload.
PATCH /v2/<name>/blobs/uploads/<uuid> Blob Upload Upload a chunk of data for the specified upload.
PUT /v2/<name>/blobs/uploads/<uuid> Blob Upload Complete the upload specified by uuid, optionally appending the body as the final chunk.
DELETE /v2/<name>/blobs/uploads/<uuid> Blob Upload Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout.
GET /v2/_catalog Catalog Retrieve a sorted, json list of repositories available in the registry.仓库列表

说明:

  • <reference>可以是tag或digest

  • manifests是镜像目录或索引

  • blobs是镜像实体

2 HEAD

英文:https://docs.docker.com/registry/spec/manifest-v2-2/

翻译:https://docs.docker.com.zh.xy2401.com/registry/spec/manifest-v2-2/

  • application/vnd.docker.distribution.manifest.v1+json :schema1(现有清单格式)
  • application/vnd.docker.distribution.manifest.v2+json :新的图像清单格式(schemaVersion = 2)
  • application/vnd.docker.distribution.manifest.list.v2+json :清单列表,又称“胖清单”
  • application/vnd.docker.container.image.v1+json :容器配置JSON
  • application/vnd.docker.image.rootfs.diff.tar.gzip :“图层”,作为压缩的tar
  • application/vnd.docker.image.rootfs.foreign.diff.tar.gzip :“图层”,作为永远不应被推送的压缩后的tar
  • application/vnd.docker.plugin.v1+json :插件配置JSON

实践总结:

  • application/vnd.docker.distribution.manifest.v2+json :新的图像清单格式(schemaVersion = 2)
  • 只有他是schemaVersion=2,其他全是1,也只有带这个header输出结果不一样,带其他header或不带header结果都一样

3 不同header及无header时的区别验证

3.1 以下输出是"schemaVersion": 2

# 新的图像清单格式(schemaVersion = 2)
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.distribution.manifest.v2+json'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gclife-agent-service/manifests/2022.07.07.094332  | wc -l
60

3.2 以下输出全是"schemaVersion": 1,而且结果也一样

# 无header
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}   https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# schema1(现有清单格式)
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.distribution.manifest.v1+json'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# 清单列表,又称“胖清单”
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.distribution.manifest.list.v2+json'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# 容器配置JSON
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.container.image.v1+json'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# “图层”,作为压缩的tar
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.image.rootfs.diff.tar.gzip'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# “图层”,作为永远不应被推送的压缩后的tar
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.image.rootfs.foreign.diff.tar.gzip'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

# 插件配置JSON
curl -s -v -X GET    -u ${DOCKER_REPO_USER}:${DOCKER_REPO_PASSWORD}  -H 'Accept: application/vnd.docker.plugin.v1+json'  https://${DOCKER_REPO}/v2/${DOCKER_REPO_USER}/gc-agent-service/manifests/2022.07.07.094332  | wc -l
139

4 最后

OK,看完这篇文章,你可能还想看看这篇文章【我实践:用docker registry API 获取清单并删除某仓库某tag镜像:https://blog.csdn.net/zhf_sy/article/details/126558517】
img

爱你!

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到