Skip to content

Instantly share code, notes, and snippets.

@northtyphoon
Last active December 23, 2022 23:20
Show Gist options
  • Save northtyphoon/dcf053b85c9b3a11b29d5eeaacbe2d8b to your computer and use it in GitHub Desktop.
Save northtyphoon/dcf053b85c9b3a11b29d5eeaacbe2d8b to your computer and use it in GitHub Desktop.

ACR Example

# Prerequisite
# 1) Install azure-cli, curl, jq

repo="hello-world"
tag="latest"
registry="myregistry.azurecr.io"
scope="repository:$repo:pull"
accept_header="Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, application/vnd.oci.artifact.manifest.v1+json, application/vnd.cncf.oras.artifact.manifest.v1+json, */*"

az acr update --name $registry --anonymous-pull-enabled

acr_access_token=$(curl "https://$registry/oauth2/token?service=$registry&scope=$scope" | jq -r ".access_token")

# alternative post request
# acr_access_token=$(curl -v -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=password&service=$registry&scope=$scope" "https://$registry/oauth2/token" | jq -r ".access_token")

curl -v -H "$accept_header" -H "Authorization: Bearer $acr_access_token" https://$registry/v2/$repo/manifests/$tag | jq

DockerHub Example

# Prerequisite
# 1) Install curl, jq

accept_header="Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, application/vnd.oci.artifact.manifest.v1+json,*/*"
registry_realm="https://auth.docker.io/token"
registry_service="registry.docker.io"
registry="registry.hub.docker.com"
repo="library/hello-world"
tag="latest"
scope="repository:$repo:pull"
access_token=$(curl "$registry_realm?service=$registry_service&scope=$scope" | jq -r ".access_token")
curl -v -H "$accept_header" -H "Authorization: Bearer $access_token" https://$registry/v2/$repo/manifests/$tag | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment