Skip to content

Instantly share code, notes, and snippets.

@mickaelbaron
Last active March 6, 2024 15:08
Show Gist options
  • Save mickaelbaron/354a2449991576d052820c64c5c60f28 to your computer and use it in GitHub Desktop.
Save mickaelbaron/354a2449991576d052820c64c5c60f28 to your computer and use it in GitHub Desktop.
How to list Docker images with their tags inside a Docker Registry?
#!/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