John Storey

Getting Tags Private Docker Repository

Tip of the day, cribbed from this gist. This allows you to get the image tags on an image in a private Docker Hub repository. First setup the environment variables.

These instructions assume that you have the great tool, jq installed. If you don't, why not?

UNAME=yourusername
UPASS=yourpassword
ORG=yourorganization # Might be the same as your username; mine is for the company.

Now get an authorization 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)

From there you can list the repositories. I'll assign them to a variable as well.

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

For a particular repository, REPOSITORY, you can get it's tags in order from most recent to least, with

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