簡體   English   中英

通過 REST API 查找與“最新”標簽同義的 docker 標簽

[英]Find docker tags that are synonyms of the "latest" tag via the REST API

我有一個名為troubleshooting的容器映像。 我的私有存儲庫中有 5 個不同版本的圖像。 (意思是列出了 5 個不同的圖像摘要。)

最新的圖像上有一個名為latest的標簽。 我需要一種方法來獲取同一圖像上的其他標簽。 我在構建腳本中執行此操作,因此我更願意通過 docker 擁有的 REST API 保留它。

我嘗試使用/v2/myrepository/myimage/tags/list端點,但它列出了所有標簽,而沒有按摘要將它們分解。

有沒有辦法讓標簽按摘要分解? (使用 REST API?)

目前,您需要對每個標簽執行 HEAD 請求,使用適當的接受標頭,以獲取摘要。 有人建議使用更好的標簽 API 擴展 OCI 的分發規范,但這需要一些時間才能獲得批准,然后由各種注冊管理機構實施。

這是用於查詢 Docker Hub 以獲取 docker manifest 或 manifest 列表的示例腳本(還有其他媒體類型可用於諸如 OCI 圖像/索引之類的內容):

#!/bin/sh

ref="${1:-library/ubuntu:latest}"
sha="${ref#*@}"
if [ "$sha" = "$ref" ]; then
  sha=""
fi
wosha="${ref%%@*}"
repo="${wosha%:*}"
tag="${wosha##*:}"
if [ "$tag" = "$wosha" ]; then
  tag="latest"
fi
api="application/vnd.docker.distribution.manifest.v2+json"
apil="application/vnd.docker.distribution.manifest.list.v2+json"
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
        | jq -r '.token')
curl -H "Accept: ${api}" -H "Accept: ${apil}" \
     -H "Authorization: Bearer $token" \
     -I -s "https://registry-1.docker.io/v2/${repo}/manifests/${sha:-$tag}"

以及包含docker-content-digest字段的結果標頭:

$ ./manifest-v2-head.sh
HTTP/1.1 200 OK
content-length: 1416
content-type: application/vnd.docker.distribution.manifest.list.v2+json
docker-content-digest: sha256:a0d9e826ab87bd665cfc640598a871b748b4b70a01a4f3d174d4fb02adad07a9
docker-distribution-api-version: registry/2.0
etag: "sha256:a0d9e826ab87bd665cfc640598a871b748b4b70a01a4f3d174d4fb02adad07a9"
date: Fri, 08 Oct 2021 18:04:26 GMT
strict-transport-security: max-age=31536000
ratelimit-limit: 100;w=21600
ratelimit-remaining: 100;w=21600
docker-ratelimit-source: 68.100.24.47

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM