How can I find a Docker image with a specific tag in Docker registry on the Docker command line?

Larry Cai picture Larry Cai · Jun 30, 2014 · Viewed 63.7k times · Source

I try to locate one specific tag for a Docker image. How can I do it on the command line? I want to avoid downloading all the images and then removing the unneeded ones.

In the official Ubuntu release, https://registry.hub.docker.com/_/ubuntu/, there are several tags (release for it), while when I search it on the command line,

user@ubuntu:~$ docker search ubuntu | grep ^ubuntu
ubuntu              Official Ubuntu base image                          354
ubuntu-upstart      Upstart is an event-based replacement for ...   7
ubuntufan/ping                                                0
ubuntu-debootstrap                                                   0

Also in the help of command line search https://docs.docker.com/engine/reference/commandline/search/, no clue how it can work?

Is it possible in the docker search command?

If I use a raw command to search via the Docker registry API, then the information can be fetched:

   $ curl https://registry.hub.docker.com//v1/repositories/ubuntu/tags | python -mjson.tool
   [
    {
        "layer": "ef83896b",
        "name": "latest"
    },
    .....
    {
        "layer": "463ff6be",
        "name": "raring"
    },
    {
        "layer": "195eb90b",
        "name": "saucy"
    },
    {
        "layer": "ef83896b",
        "name": "trusty"
    }
]

Answer

shadowbq picture shadowbq · Sep 17, 2015

When using CoreOS, jq is available to parse JSON data.

So like you were doing before, looking at library/centos:

$ curl -s -S 'https://registry.hub.docker.com/v2/repositories/library/centos/tags/' | jq '."results"[]["name"]' |sort
"6"
"6.7"
"centos5"
"centos5.11"
"centos6"
"centos6.6"
"centos6.7"
"centos7.0.1406"
"centos7.1.1503"
"latest"

The cleaner v2 API is available now, and that's what I'm using in the example. I will build a simple script docker_remote_tags:

#!/usr/bin/bash
curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$@/tags/" | jq '."results"[]["name"]' |sort

Enables:

$ ./docker_remote_tags library/centos
"6"
"6.7"
"centos5"
"centos5.11"
"centos6"
"centos6.6"
"centos6.7"
"centos7.0.1406"
"centos7.1.1503"
"latest"

Reference:

jq: https://stedolan.github.io/jq/ | apt-get install jq