Skip to content

Instantly share code, notes, and snippets.

@kizbitz
Last active April 3, 2024 08:47
Show Gist options
  • Star 73 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721 to your computer and use it in GitHub Desktop.
Save kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721 to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub organization account
#!/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
@hans-fischer
Copy link

Thanks!

@elkh510
Copy link

elkh510 commented Mar 9, 2021

Thank you!
Very useful!

@ConanMishler
Copy link

Thanks, useful!

@Roybge
Copy link

Roybge commented Nov 11, 2021

Amazing , simple and effective , thank you !

@ludenus
Copy link

ludenus commented Nov 22, 2021

Thanks you!
Your script is exactly what I was looking for!
I have to modify it to fetch paginated results, here it is with paging support
https://gist.github.com/ludenus/9c2770ec85676322bd964df75508f3b0

@blaisedias
Copy link

Thanks - worked a treat

@syneart
Copy link

syneart commented Jan 2, 2023

Thanks for the code snippet. I made the project and Docker Hub list retrieving part is based on it.
https://github.com/syneart/dockeReg
Project "dockeReg" support Docker Hub and Docker Registry (and with OAuth2).

@BCsabaEngine
Copy link

npm package for public tags: https://www.npmjs.com/package/docker-hub-tags

@MarioAlbo
Copy link

Thank you so much. This help me a lot to pull every image from my repository to migrate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment