Last active
March 6, 2024 15:08
-
-
Save mickaelbaron/354a2449991576d052820c64c5c60f28 to your computer and use it in GitHub Desktop.
How to list Docker images with their tags inside a Docker Registry?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://github.com/kwk/docker-registry-setup#manual-token-based-workflow-to-list-repositories | |
# https://github.com/mayflower/docker-ls | |
# Check parameters | |
if [ $# -eq 0 ]; then | |
echo "Login and password are missing (user:password)." | |
exit 1 | |
fi | |
userPassword=$1 | |
token() { | |
registryURL="https://PRIVATE_REGISTRY_URL" | |
realm="$registryURL/dockerauth/auth" | |
service="Authentication" | |
scope=$1 | |
authURL="$realm?service=$service&scope=$scope" | |
token=$(curl -ks -H "Authorization: Basic $(echo -n $userPassword | base64)" "$authURL") | |
token=$(echo $token | jq .token | tr -d '"') | |
} | |
token "registry:catalog:*" | |
tokenCatalog=$token | |
curl -sSL -H "Authorization: Bearer $tokenCatalog" "$registryURL/v2/_catalog" | jq -r '.repositories[]' | while read imagename ; do | |
echo $imagename | |
token "repository:$imagename:*" | |
tokenRepository=$token | |
curl -sSL -H "Authorization: Bearer $tokenRepository" "$registryURL/v2/$imagename/tags/list" | jq -r '.tags[]?' | while read imagetag ; do | |
echo " "$imagetag | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment