问题
I'm trying to get the labels of an image without pulling it.
For example: in docker-hub, on my username (stavalfi
), in repo: projecty
: https://hub.docker.com/v2/repositories/stavalfi/projecty/tags
I want to get all the labels of this image.
Following this guide: https://hackernoon.com/inspecting-docker-images-without-pulling-them-4de53d34a604
and this: https://docs.docker.com/registry/spec/api/#pulling-a-layer
I tried to reach to: http://$REGISTRY_ADDRESS/v2/$image/blobs/$digest
:
https://hub.docker.com/v2/stavalfi/projecty/blobs/sha256:7701c1411c0e438c5bfb1d7b4c1f337ee75b4a3a1d8492fc3b608cdc2b320a9d
but the result is a 404.
What is the problem?
I can't use skopeo
because it can't inspect registries with an HTTP connection (insecure).
回答1:
this worked for me, you can try this
curl 'https://registry.hub.docker.com/v2/repositories/< username>/<repo>/tags/'|jq '."results"[]["name"]'
regarding blob, token need to be generated then use this token for 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' \
)"
now get the manifest of the image
curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
'https://registry-1.docker.io/v2/<username>/<repo>/manifests/<latest>' \
| jq '.'
now get the blob for that image
curl \
--silent \
--request 'GET' \
--header "Authorization: Bearer ${TOKEN}" \
"https://registry-1.docker.io/v2/<username>/<repo>/manifests/19" \
| jq -r '.fsLayers[].blobSum'
the above command gives the list of digests which can be used to fetch the image
set the following variable
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/get-labels-of-remote-docker-image