-
-
Save kizbitz/175be06d0fbbb39bc9bfa6c0cb0d4721 to your computer and use it in GitHub Desktop.
#!/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 |
Thanks very much
This really helped. As docker hub documentation was not easy to traverse around on API calls .. This saved ton of my hours.. thank you .
Thank you, it was very useful!
👍
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 ?
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'
@kizbitz : Thank you for your help.
Does anyone have direct link to the documentation. Really not straight forward from docker webpage
Thanks!
Thank you!
Very useful!
Thanks, useful!
Amazing , simple and effective , thank you !
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
Thanks - worked a treat
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).
npm package for public tags: https://www.npmjs.com/package/docker-hub-tags
Thank you so much. This help me a lot to pull every image from my repository to migrate it.
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