List all images in a Docker Registry over SSH

Thursday, November 21, 2019

Tags:   Bash Docker

Summary

Command to list all the images in a Docker registry over SSH

Explanation and code

Warning: This solution isn't pretty.

By default there's no clean way to list all the Docker images in a remote docker registry, especially if you're using SSH without a keypair or certificate of any kind (as is the case in my setup, yay!).

Instead you have to first query the registry API _catalog endpoint to get a list of all the repositories, and then run separate queries on each of the repositories that were returned to list all the images.

Ergo this hideous monstrosity:

ssh -t user@host.goes.here '
for repo in $(curl --silent localhost:5000/v2/_catalog | jq -r .repositories[]); do
curl --silent localhost:5000/v2/${repo}/tags/list | jq .;
done;'

Example Output

{
  "name": "cer-api",
  "tags": [
    "deploy-reorg.32c0868",
    "deploy-reorg.latest",
    "deploy-reorg.d97c8ab",
    "PR-2.32c0868",
    "PR-2.latest",
    "master.1c4e7b9",
  ]
}
{
  "name": "research-hub-api",
  "tags": [
    "deploy-reorg.a895ff3",
    "deploy-reorg.latest",
    "master.92bf04c",
    "master.latest",
    "fix-response-charset.2992069",
    "fix-response-charset.latest",
    "local-deployment.40b0435",
    "local-deployment.latest",
  ]
}
{
  "name": "research-hub-db",
  "tags": [
    "deploy-reorg.74f2d9b",
    "deploy-reorg.latest",
    "master.fd59cf3",
    "master.latest",
    "local-deployment.09ef00e",
    "local-deployment.latest",
  ]
}