Skip to content

Instantly share code, notes, and snippets.

@ademidoff
Created December 14, 2023 15:43
Show Gist options
  • Save ademidoff/a5da14768d472ec4c372950d421fa050 to your computer and use it in GitHub Desktop.
Save ademidoff/a5da14768d472ec4c372950d421fa050 to your computer and use it in GitHub Desktop.
List Docker Image Tags
#!/usr/bin/env bash
# Gets all tags for a given docker image.
# Examples:
# retrieve all tags for a single library
# docker-tags "library/redis"
# retrieve all tags for multiple libraries
# docker-tags "library/mongo" "library/redis" "microsoft/nanoserver" "microsoft/dotnet"
# retrieve first 10 tags for multiple libraries
# docker-tags "library/mongo" "library/redis" "microsoft/nanoserver" "microsoft/dotnet" | jq --raw-output '.[][0:9]'
docker-tags() {
arr=("$@")
if ! type -p jq &>/dev/null; then
echo "Error: you need 'jq' to be installed to run this script."
fi
for item in "${arr[@]}"; do
tokenUri="https://auth.docker.io/token"
data=("service=registry.docker.io" "scope=repository:$item:pull")
token="$(curl --silent --get --data-urlencode ${data[0]} --data-urlencode ${data[1]} $tokenUri | jq --raw-output '.token')"
listUri="https://registry-1.docker.io/v2/$item/tags/list"
authz="Authorization: Bearer $token"
result="$(curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $token" $listUri | jq --raw-output '.')"
# echo $result | jq --raw-output '.[]'
echo $result
done
}
docker-tags "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment