Last active
April 17, 2023 23:30
-
-
Save kizbitz/e59f95f7557b4bbb8bf2 to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub user account.
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 | |
# Example for the Docker Hub V2 API | |
# Returns all imagas and tags associated with a Docker Hub user account. | |
# Requires 'jq': https://stedolan.github.io/jq/ | |
# set username and password | |
UNAME="" | |
UPASS="" | |
# ------- | |
set -e | |
echo | |
# aquire 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 for the user account | |
REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/?page_size=100 | jq -r '.results|.[]|.name') | |
# build a list of all images & tags | |
for i in ${REPO_LIST} | |
do | |
# get tags for repo | |
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/?page_size=100 | jq -r '.results|.[]|.name') | |
# build a list of images from tags | |
for j in ${IMAGE_TAGS} | |
do | |
# add each tag to list | |
FULL_IMAGE_LIST="${FULL_IMAGE_LIST} ${UNAME}/${i}:${j}" | |
done | |
done | |
# output | |
for i in ${FULL_IMAGE_LIST} | |
do | |
echo ${i} | |
done |
Environmental Science:python3.7+flask dokcer:Docker version 18.06.1-ce
False hints:line 19: jq: command not found
(23) Failed writing body
problem:ORG="" I don't know what to write.
@Jack-qing. you need jq. you can install one from brew (brew install jq
). let's see if there is any problem after you have jq
Where can I find the official documentation for this docker hub v2 api?
Just to add here: This will fetch any user's public repos irrespective of the authorised user.
Worked like wonders, for my naive repos <3
There is a page_size parameter specified in the REST API call which means only 100 images at a time will get listed down. What if I want to list down all images?
thanks for the script
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environmental Science:python3.7+flask dokcer:Docker version 18.06.1-ce

False hints:line 19: jq: command not found
(23) Failed writing body
problem:ORG="" I don't know what to write.