Last active
February 20, 2026 04:08
-
-
Save bunsyy/f6c6eeb12c9d9b053c5f56397c233772 to your computer and use it in GitHub Desktop.
This script lists all images that belong to an organisation.
This file contains hidden or 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 | |
| # Example for the Docker Hub V2 API | |
| # Returns a json that list all images and tags associated with a Docker Hub organization account. | |
| # Requires 'jq': https://stedolan.github.io/jq/ | |
| # set username, password, and organization | |
| UNAME="" | |
| UPASS="" | |
| ORG="" | |
| # ------- | |
| OUTPUT="docker-images.json" | |
| set -e | |
| echo "Retrieving token ..." | |
| TOKEN=$(curl -s -H "Content-Type: application/json" \ | |
| -X POST \ | |
| -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' \ | |
| https://hub.docker.com/v2/users/login/ | jq -r .token) | |
| echo "Retrieving repository list ..." | |
| REPO_LIST=$(curl -s \ | |
| -H "Authorization: JWT ${TOKEN}" \ | |
| "https://hub.docker.com/v2/repositories/${ORG}/?page_size=100" \ | |
| | jq -r '.results[].name') | |
| echo "Building JSON ..." | |
| # start JSON object | |
| echo "{" > "$OUTPUT" | |
| FIRST_REPO=true | |
| for REPO in $REPO_LIST | |
| do | |
| echo "Processing repo: $REPO" | |
| IMAGE_TAGS=$(curl -s \ | |
| -H "Authorization: JWT ${TOKEN}" \ | |
| "https://hub.docker.com/v2/repositories/${ORG}/${REPO}/tags/?page_size=100" \ | |
| | jq -r '.results[].name') | |
| # comma handling | |
| if [ "$FIRST_REPO" = true ]; then | |
| FIRST_REPO=false | |
| else | |
| echo "," >> "$OUTPUT" | |
| fi | |
| echo -n " \"$REPO\": [" >> "$OUTPUT" | |
| FIRST_TAG=true | |
| for TAG in $IMAGE_TAGS | |
| do | |
| if [ "$FIRST_TAG" = true ]; then | |
| FIRST_TAG=false | |
| else | |
| echo -n ", " >> "$OUTPUT" | |
| fi | |
| echo -n "\"$TAG\"" >> "$OUTPUT" | |
| done | |
| echo -n "]" >> "$OUTPUT" | |
| done | |
| echo "" >> "$OUTPUT" | |
| echo "}" >> "$OUTPUT" | |
| echo "Saved to $OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment