bkuhl
(Ben Kuhl)
May 21, 2017, 11:44pm
1
I’m trying to use the API to list the tags for DockerHub repositories. We’ll see I’m trying for bkuhl/game-watcher/. Both https://hub.docker.com/v2/bkuhl/game-watcher/tags and /v2/bkuhl/game-watcher/tags/list return 404s (when I’m authenticated). The only documentation on this I can find is located at https://docs.docker.com/registry/spec/api/#listing-image-tags . Though I’m not completely sure this documentation is for DockerHub itself.
How can I list the tags for a repository?
bkuhl
(Ben Kuhl)
May 21, 2017, 11:53pm
2
Apparently the URL is https://hub.docker.com/v2/repositories/bkuhl/game-watcher/tags as of some random gist I found online. Is there any official documentation for this?
acourtis
(Acourtis)
August 30, 2017, 4:58pm
3
See CLI utility: https://www.npmjs.com/package/docker-browse
Allows enumeration of tags and images.
tsenkov
(Tsenkov)
May 2, 2018, 8:24am
4
Does anyone know what is the reason this hasn’t been implemented for the CLI tooling of docker?
Shouldn’t it be something as simple as this?
$ docker image search --list-tags <path/to/repo>
ssbarnea
(Sorin Sbarnea)
March 7, 2019, 2:21pm
5
True, I am still wondering how to search on tags, the website is useless two because it has no search and a pagination of ~20 tags, making impossible to find the tag on active repos.
and I’m sure it used to have a much more compact view?
But, I agree, its current form is useless. Not ordered, not searchable.
create0
(Create0)
July 16, 2019, 7:53pm
7
Thank you so much for truly a veritable knowldege.It really worked for me. The key idea behind it is pretty amazing and glad to know about it.
zzhouqianq
(Zzhouqianq)
February 7, 2020, 7:41am
8
function listTags() {
local repo=${1}
local size=${2:-25}
local page=${3:-1}
[ -z "${repo}" ] && echo "Usage: listTags <repoName> [size] [pageIndex]" 1>&2 && return 1
curl "https://registry.hub.docker.com/api/content/v1/repositories/public/library/${repo}/tags?page=${page}&page_size=${size}" 2>/dev/null | jq -r '.results[].name' | sort
}
have a try on this function, you need to install jq first (sudo apt install jq).
example usage:
listTags ubuntu
listTags ubuntu 10
atzannes
(Alexandros Tzannes)
October 13, 2021, 7:58pm
9
I extended the code by @zzhouqianq to grab all the tags, doing multiple round-trips to DockerHub when necessary. I hope someone finds it useful.
function listAllTags() {
local repo=${1}
local page_size=${2:-100}
[ -z "${repo}" ] && echo "Usage: listTags <repoName> [page_size]" 1>&2 && return 1
local base_url="https://registry.hub.docker.com/api/content/v1/repositories/public/library/${repo}/tags"
local page=1
local res=$(curl "${base_url}?page_size=${page_size}&page=${page}" 2>/dev/null)
local tags=$(echo ${res} | jq --raw-output '.results[].name')
local all_tags="${tags}"
local tag_count=$(echo ${res} | jq '.count')
((page_count=(${tag_count}+${page_size}-1)/${page_size})) # ceil(tag_count / page_size)
for page in $(seq 2 $page_count); do
tags=$(curl "${base_url}?page_size=${page_size}&page=${page}" 2>/dev/null | jq --raw-output '.results[].name')
all_tags="${all_tags}${tags}"
done
echo "${all_tags}" | sort
}
Cool but, 2 years later is this still the “official” way to list tags on an image?
got an answer? or find out what is the current official way?
rimelek
(Ákos Takács)
May 12, 2024, 7:25pm
12
You mean like hub-tool? It is included in Docker Desktop, but you can install anywhere.
hub-tool tag ls bkuhl/game-watcher
or as json
hub-tool tag ls bkuhl/game-watcher --format json
hub-tool already existed then, but open source registry softwares like Harbor still have only API interfaces as far as I know.
If anyone is looking for a Docker Hub API reference, that exists as well
lustar170
(Lustar)
February 12, 2025, 3:10am
13
Official documentation about API URL.
Use it with Bearer Token with PAT.