Forked from kizbitz/dockerhub-v2-api-organization.sh
Created
September 27, 2020 10:52
-
-
Save ArjunDandagi/2f487a4e771752a8a5efc81a0bd46a2c to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub organization account
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 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="" | |
# ------- | |
set -e | |
echo | |
# get token | |
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) | |
# get list of repositories | |
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') | |
# output images & tags | |
echo | |
echo "Images and tags for organization: ${ORG}" | |
echo | |
for i in ${REPO_LIST} | |
do | |
echo "${i}:" | |
# tags | |
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${ORG}/${i}/tags/?page_size=100 | jq -r '.results|.[]|.name') | |
for j in ${IMAGE_TAGS} | |
do | |
echo " - ${j}" | |
done | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment