Script for listing of all private repos and tags in DockerHub

Hello everyone. I’m trying to find a script that lists all the Docker private images (and related tags) of my account. I found this:

#!/bin/bash

# Example for the Docker Hub V2 API
# Returns all imagas and tags associated with a Docker Hub user account.
# Requires 'jq': https://stedolan.github.io/jq/

# set username and password
UNAME=""
UPASS=""

# -------

set -e
echo

# aquire 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 for the user account
REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/?page_size=100 | jq -r '.results|.[]|.name')

# build a list of all images & tags
for i in ${REPO_LIST}
do
  # get tags for repo
  IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${UNAME}/${i}/tags/?page_size=100 | jq -r '.results|.[]|.name')

  # build a list of images from tags
  for j in ${IMAGE_TAGS}
  do
    # add each tag to list
    FULL_IMAGE_LIST="${FULL_IMAGE_LIST} ${UNAME}/${i}:${j}"
  done
done

# output
for i in ${FULL_IMAGE_LIST}
do
  echo ${i}
done

but I’m getting jq: error (at <stdin>:1): Cannot iterate over null (null)
Apart from this, Is there another way to archive what I’m looking for?

You can just use hub-tool
organization=“your organization or username”

hub-tool repo ls "$organization" --format json | jq '.[] | select(.IsPrivate)'

hub-tool is installed with Docker Desktop by default

2 Likes

Hello, thanks for your reply.
I was able to fix the script, but I tried also your solution. When I try ./hub-tool repo ls "$organization" --format json | jq '.[] | select(.IsPrivate) (I’m using Ubuntu), I get this:
> (looks like it’s waiting for inputs)

I forgot to use the closing apostrophe at the end. I fixed the command in my previous post.

1 Like

Tank you for your help!