Skip to content

Instantly share code, notes, and snippets.

@lionello
Last active April 2, 2025 00:12
Show Gist options
  • Save lionello/8fb32ee065774b934ab9af62fd269e39 to your computer and use it in GitHub Desktop.
Save lionello/8fb32ee065774b934ab9af62fd269e39 to your computer and use it in GitHub Desktop.
Shell script to inspect a Docker image on a remote registry
#!/bin/bash
# Canonical version: https://gist.github.com/lionello/8fb32ee065774b934ab9af62fd269e39
# Inspired by https://stackoverflow.com/a/69300514/2017049
REGISTRY="registry-1.docker.io"
ref="${1:-library/ubuntu:latest}"
repo="${ref%:*}"
tag="${ref##*:}"
token=$(curl -sSLf "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.list.v2+json" \
-H "Authorization: Bearer $token" \
-sSLf "https://$REGISTRY/v2/${repo}/manifests/${tag}" \
| jq -re '.manifests[] | select(.platform.architecture == "amd64" and .platform.os == "linux") | .digest')
config=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
-H "Authorization: Bearer $token" \
-sSLf "https://$REGISTRY/v2/${repo}/manifests/${digest:-$tag}" \
| jq -r .config.digest)
curl -H "Accept: application/vnd.docker.container.image.v1+json" \
-H "Authorization: Bearer $token" \
-sSLf "https://$REGISTRY/v2/${repo}/blobs/${config}" | jq .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment