I try to locate one specific tag for a Docker image. How can I do it on the command line? I try to avoid to download all and remove unneeded images.
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"
}
]
As far as I know, the CLI does not allow searching/listing tags in a repository.
But if you know which tag you want, you can pull that explicitly by adding a colon and the image name:
docker pull ubuntu:saucy
For a script that works with Oauth bearer tokens on Docker hub, try this:
Listing the tags of a Docker image on a Docker hub through the HTTP API
The v2 API seems to use some kind of pagination, so that it does not return all the available tags. This is clearly visible in projects such as
python
(orlibrary/python
). Even after quickly reading the documentation, I could not manage to work with the API correctly (maybe it is the wrong documentation).Then I rewrote the script using the v1 API, and still using
jq
:The full script is available at: https://bitbucket.org/denilsonsa/small_scripts/src/default/docker_remote_tags.sh
I've also written (in Python) an improved version that aggregates tags that point to the same version: https://bitbucket.org/denilsonsa/small_scripts/src/default/docker_remote_tags.py
I wrote a command line tool to simplify searching DockerHub repo tags, available in my PyTools GitHub repo. It's simple to use with various command line switches, but most basically:
It's even available as a docker image and can take multiple repos:
If you want to embed in scripts use -q / --quiet to get just the tags, like normal docker commands:
This script (docker-show-repo-tags.sh) should work for any Docker enabled host that has curl, sed, grep, and sort. This was updated to reflect the fact the repository tag URLs changed.
This older version no longer works.
This is the output for a simple example:
Reimplementation of the previous post, using Python over sed/awk: