Skip to content

Instantly share code, notes, and snippets.

@kizbitz
Last active April 7, 2026 15:52
Show Gist options
  • Select an option

  • Save kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721 to your computer and use it in GitHub Desktop.

Select an option

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
@EliRibble

Copy link
Copy Markdown

Just wanted to say thanks, this helped me a great deal today

@binhex

binhex commented Mar 16, 2017

Copy link
Copy Markdown

@kizbitz ive been searching but i cant find anything that shows me how to programatically modify an existing docker tag name on a repo for docker hub, is this possible or is it purely listing tags only, no editing?.

@grayaii

grayaii commented Mar 30, 2017

Copy link
Copy Markdown

Just came here to say this helped me too! Thanks!

@thiagozs

Copy link
Copy Markdown

Helped me alot, Thanks for sharing.

@mlippens

mlippens commented Oct 4, 2017

Copy link
Copy Markdown

Thanks, this works well :)

@jacobscarter

Copy link
Copy Markdown

In case anyone here has trouble. In the above example the variable ${i} was saving with a new line \r at the end. So the second curl to get tags was not returning anything. Here is the fix:

echo
for i in ${REPO_LIST}
do
  echo "${i}:"
  cr=$'\r'
  i="${i%$cr}"
  # 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}

@Akhilkm

Akhilkm commented Feb 3, 2018

Copy link
Copy Markdown

Is there a way to get the list of Organization in my docker hub account. Thanks in advance. :)

@nomisbeme

Copy link
Copy Markdown

Thanks for posting this. One word of caution, this script seems to return the most recently updated 100 tags for each image. If your image has more than 100 tags the results will be incomplete. Fixing this requires following the chain of URIs provided in "next"

@joequery

Copy link
Copy Markdown

Thanks for this!

@ORESoftware

Copy link
Copy Markdown

to get a list of all nodejs images, I used:

org="library/node/tags"

REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${org}/?page_size=100 | jq -r '.results|.[]|.name')

@ohadbenita

Copy link
Copy Markdown

What would I need to get a list of all image tags for a certain docker image, let's say homeassistant/home-assistant ?

@alexanderilyin

Copy link
Copy Markdown

I had to use Docker Hub API v2 for private repo in order to get list of all tags, example is here if anyone needs it:

cc @ohadbenita

@Jack-qing

Copy link
Copy Markdown

Thanks very much

@spakal1

spakal1 commented Dec 3, 2018

Copy link
Copy Markdown

This really helped. As docker hub documentation was not easy to traverse around on API calls .. This saved ton of my hours.. thank you .

@teodorescuserban

Copy link
Copy Markdown

Thank you, it was very useful!
👍

@kamalgrover

Copy link
Copy Markdown

Is there a way to get the list of Organization in my docker hub account. Thanks in advance. :)

@Akhilkm: Did you find the way to do this ?

@kizbitz

kizbitz commented Mar 23, 2020

Copy link
Copy Markdown
Author

@kamalgrover @Akhilkm

You can get the list of organizations with: curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/user/orgs/?page_size=50 | jq -r '.results|.[]|.orgname'

@kamalgrover

Copy link
Copy Markdown

@kizbitz : Thank you for your help.

@kenjox

kenjox commented Aug 6, 2020

Copy link
Copy Markdown

Does anyone have direct link to the documentation. Really not straight forward from docker webpage

@hans-fischer

Copy link
Copy Markdown

Thanks!

@elkh510

elkh510 commented Mar 9, 2021

Copy link
Copy Markdown

Thank you!
Very useful!

@ConanMishler

Copy link
Copy Markdown

Thanks, useful!

@Roybge

Roybge commented Nov 11, 2021

Copy link
Copy Markdown

Amazing , simple and effective , thank you !

@ludenus

ludenus commented Nov 22, 2021

Copy link
Copy Markdown

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
Copy Markdown

Thanks - worked a treat

@syneart

syneart commented Jan 2, 2023

Copy link
Copy Markdown

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
Copy Markdown

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

@yeyoonme

yeyoonme commented Apr 3, 2024

Copy link
Copy Markdown

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