Skip to content

Instantly share code, notes, and snippets.

@jmansour
Created October 23, 2019 10:45
Show Gist options
  • Save jmansour/92cf279b30e5c1e4099408051e169885 to your computer and use it in GitHub Desktop.
Save jmansour/92cf279b30e5c1e4099408051e169885 to your computer and use it in GitHub Desktop.
Shell script to get all image digests from a DockerHub registry
#!/bin/bash
# based on https://stackoverflow.com/questions/41808763/how-to-determine-the-docker-image-id-for-a-tag-via-docker-hub-api/41830007#41830007
REPOSITORY="underworldcode/underworld2"
# TARGET_TAG=$2
# get authorization token
TOKEN=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:pull" | jq -r .token)
# find all tags
ALL_TAGS=$(curl -s -H "Authorization: Bearer $TOKEN" https://index.docker.io/v2/$REPOSITORY/tags/list | jq -r .tags[])
# get image digest for target
# TARGET_DIGEST=$(curl -s -D - -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/$REPOSITORY/manifests/$TARGET_TAG | grep Docker-Content-Digest | cut -d ' ' -f 2)
# for each tags
for tag in ${ALL_TAGS[@]}; do
# get image digest
digest=$(curl -s -D - -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/$REPOSITORY/manifests/$tag | grep Docker-Content-Digest | cut -d ' ' -f 2)
# check digest
# if [[ $TARGET_DIGEST = $digest ]]; then
echo "$tag $digest"
# fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment