Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save killbus/875b180741951980798c8fdeff04c46d to your computer and use it in GitHub Desktop.
Save killbus/875b180741951980798c8fdeff04c46d to your computer and use it in GitHub Desktop.

digest-v2.sh

#!/bin/sh

ref="${1:-library/ubuntu:latest}"
repo="${ref%:*}"
tag="${ref##*:}"
acceptM="application/vnd.docker.distribution.manifest.v2+json"
acceptML="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: ${acceptM}" \
     -H "Accept: ${acceptML}" \
     -H "Authorization: Bearer $token" \
     -I -s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}"

compare

./digest-v2.sh library/busybox:latest

Content-Length: 2080
Content-Type: application/vnd.docker.distribution.manifest.list.v2+json
Docker-Content-Digest: sha256:d366a4665ab44f0648d7a00ae3fae139d55e32f9712c67accd604bb55df9d05a
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:d366a4665ab44f0648d7a00ae3fae139d55e32f9712c67accd604bb55df9d05a"
Date: Sun, 11 Oct 2020 21:04:59 GMT
Strict-Transport-Security: max-age=31536000

docker image inspect busybox:latest --format '{{json .RepoDigests}}' | jq .

  "busybox@sha256:d366a4665ab44f0648d7a00ae3fae139d55e32f9712c67accd604bb55df9d05a"
]

See https://stackoverflow.com/questions/42137511/how-do-i-check-if-my-local-docker-image-is-outdated-without-pushing-from-somewh/64309017#64309017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment