Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

EliRibble commented Jan 18, 2017

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

@binhex
Copy link

binhex commented Mar 16, 2017

@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
Copy link

grayaii commented Mar 30, 2017

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

@thiagozs
Copy link

thiagozs commented Jun 30, 2017

Helped me alot, Thanks for sharing.

@mlippens
Copy link

mlippens commented Oct 4, 2017

Thanks, this works well :)

@jacobscarter
Copy link

jacobscarter commented Dec 4, 2017

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

Akhilkm commented Feb 3, 2018

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

@nomisbeme
Copy link

nomisbeme commented Feb 6, 2018

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

joequery commented Mar 13, 2018

Thanks for this!

@ORESoftware
Copy link

ORESoftware commented Jun 21, 2018

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

ohadbenita commented Oct 20, 2018

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

alexanderilyin commented Nov 15, 2018

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

Jack-qing commented Nov 15, 2018

Thanks very much

@spakal1
Copy link

spakal1 commented Dec 3, 2018

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

teodorescuserban commented Feb 21, 2019

Thank you, it was very useful!
👍

@kamalgrover
Copy link

kamalgrover commented Mar 23, 2020

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
Copy link
Author

kizbitz commented Mar 23, 2020

@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

kamalgrover commented Mar 24, 2020

@kizbitz : Thank you for your help.

@kenjox
Copy link

kenjox commented Aug 6, 2020

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

@hans-fischer
Copy link

hans-fischer commented Jan 3, 2021

Thanks!

@elkh510
Copy link

elkh510 commented Mar 9, 2021

Thank you!
Very useful!

@ConanMishler
Copy link

ConanMishler commented Jul 9, 2021

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

blaisedias commented Apr 12, 2022

Thanks - worked a treat

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