Skip to content

Instantly share code, notes, and snippets.

@OndrejP
Last active November 28, 2019 00:52
Show Gist options
  • Save OndrejP/a2386d08e5308b0776c0 to your computer and use it in GitHub Desktop.
Save OndrejP/a2386d08e5308b0776c0 to your computer and use it in GitHub Desktop.
list all images on Docker Register v2
#!/bin/bash
export Register=https://register.example.com
export cLink="/v2/_catalog?n=10"
export cFile=docker.register.catalog
export tFile=docker.register.tags
export wgetC="wget -O- -q -S "
# Usage with user/password
# export wgetC="wget -O- -q -S --user=ondra --password=heslo "
function listFullCatalog {
while true; do
# If you need user/password , add --user= and --pasword= ; Thanks rmetzger
${wgetC} "${Register}${cLink}" \
2>${cFile} \
| json_pp -t json | grep -F " " | cut -d\" -f2 | listTags
cLink=`grep Link ${cFile} 2>/dev/null | cut -d\< -f2 | cut -d\> -f1`
if [ ! -n "${cLink}" ] ; then break; fi
done
}
function listTags {
cat - | while read image; do
tLink="/v2/${image}/tags/list?n=10"
while true; do
# If you need user/password , add --user= and --pasword= ; Thanks rmetzger
${wgetC} "${Register}${tLink}" \
2>${tFile} \
| json_pp -t json | grep -F " " | cut -d\" -f2 | sed "s@^@${image}:@"
tLink=`grep Link ${tFile} 2>/dev/null | cut -d\< -f2 | cut -d\> -f1`
if [ ! -n "${tLink}" ] ; then break; fi
done
done
}
listFullCatalog
@inscrutabledude
Copy link

I get an error:
"malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/bin/json_pp line 44."

I think it's auth related tho because when i just try a simple wget with none of the processing I get this:

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
Www-Authenticate: Bearer realm="https://location.com:5001/auth",service="Docker registry",scope="registry:catalog:*"
X-Content-Type-Options: nosniff
Date: Wed, 25 Jan 2017 19:44:20 GMT
Content-Length: 134

Do you have any advice on how I could change/correct this script to work?

Thanks in advance!

@rmetzger
Copy link

rmetzger commented Jan 3, 2018

to fix, pass --user and --password to wget. Like this:

wget --user=rmetzger --password=XXXXXXX -O- -q -S "${Register}${cLink}" \

@flickerfly
Copy link

Other useful wget options:
--header="key:value" is useful for an API key to be passed in
--no-check-certificates is useful when using self-signed certs

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