我试着在不拉的情况下得到图像的标签。
例如:在停靠中心,在我的用户名(stavalfi)上,在repo:projecty:https://hub.docker.com/v2/repositories/stavalfi/projecty/tags中
我想要得到这张图片的所有标签。
遵循本指南:https://hackernoon.com/inspecting-docker-images-without-pulling-them-4de53d34a604
这个:https://docs.docker.com/registry/spec/api/#pulling-a-layer
我试着联系到:http://$REGISTRY_ADDRESS/v2/$image/blobs/$digest
但结果是404。
有什么问题吗?
我不能使用skopeo ,因为它不能检查带有HTTP连接的注册中心(不安全).
发布于 2020-06-28 19:48:09
您可以在码头舱单的第一层中找到标签:
$ repo=stavalfi/k8test-monitoring
$ token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
| jq -r '.token')
$ curl -s -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/${repo}/manifests/latest" \
| jq ".history[0].v1Compatibility" -r | jq .config.Labels
{
"latest-hash": "dc971f310bd0b172fd0379cc9a1810f209c9a9604a28da14cef36457",
"latest-tag": "1.3.4"
}Update: v2注册表API稍微干净一些,但是还需要一个curl:
$ repo=stavalfi/k8test-monitoring
$ token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
| jq -r '.token')
$ digest=$(curl -s -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/${repo}/manifests/latest" \
| jq .config.digest -r)
$ curl -s -L -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/${repo}/blobs/$digest" \
| jq .config.Labels
{
"latest-hash": "dc971f310bd0b172fd0379cc9a1810f209c9a9604a28da14cef36457",
"latest-tag": "1.3.4"
}对于一个更通用的用例,下面是一个脚本,可以在没有下载完整映像的情况下提取停靠中心上任何公共映像的配置:
#!/bin/sh
repo=${1:-library/ubuntu}
tag=${2:-latest}
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
| jq -r '.token')
digest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
-H "Authorization: Bearer $token" \
-s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}" | jq -r .config.digest)
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
-H "Authorization: Bearer $token" \
-s -L "https://registry-1.docker.io/v2/${repo}/blobs/${digest}" | jq .只需确保包含官方图像的“库”前缀:
$ ./get-config-v2.sh library/alpine 3.9
{
"architecture": "amd64",
"config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh"
],
"ArgsEscaped": true,
"Image": "sha256:186eda4636e895d982896312666e472a2d62aab1490608701e1b3438ac6649e7",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
....自从第一次发布这个答案以来,我还创建了雷格,其中包含了regctl命令。这将处理身份验证,允许您在不使用TLS或使用自签名证书的情况下配置注册表,解析多平台映像,并包括对Go模板的支持,以提取所需的特定字段:
$ regctl image config regclient/regsync:latest --format '{{ jsonPretty .Config.Labels }}'
{
"maintainer": "",
"org.opencontainers.image.authors": "Regclient contributors",
"org.opencontainers.image.created": "2021-04-02T18:55:09Z",
"org.opencontainers.image.description": "",
"org.opencontainers.image.documentation": "https://github.com/regclient/regclient",
"org.opencontainers.image.licenses": "Apache 2.0",
"org.opencontainers.image.revision": "5a6a1d95524b9c1c2d38a5af7ab744742f8d55e9",
"org.opencontainers.image.source": "git://github.com/regclient/regclient.git",
"org.opencontainers.image.title": "regsync",
"org.opencontainers.image.url": "https://github.com/regclient/regclient",
"org.opencontainers.image.vendor": "",
"org.opencontainers.image.version": "v0.3.0"
}发布于 2020-06-26 23:12:59
这个对我有用,你可以试试这个
curl 'https://registry.hub.docker.com/v2/repositories/< username>/<repo>/tags/'|jq '."results"[]["name"]' 对于blob,需要生成令牌,然后将此令牌用于blob。
export TOKEN=\
"$(curl \
--silent \
--header 'GET' \
"https://auth.docker.io/token?
service=registry.docker.io&scope=repository:<username>/<repo>:pull,push" \
| jq -r '.token' \
)" 现在获取图像的清单
curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
'https://registry-1.docker.io/v2/<username>/<repo>/manifests/<latest>' \
| jq '.'现在给那个图像取个小块
curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/<username>/<repo>/manifests/19" \
| jq -r '.fsLayers[].blobSum' 上面的命令给出了可用于获取图像的摘要列表。
设置以下变量
DIGEST=<SHA:somevalue>
curl \
--silent \
--location \
--request GET \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/<username>/<repo>/blobs/${DIGEST}" >
"${DIGEST/*:/}.gz"https://stackoverflow.com/questions/62600611
复制相似问题