How can I list tags for a repository?

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?

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?

See CLI utility: https://www.npmjs.com/package/docker-browse

Allows enumeration of tags and images.

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>
4 Likes

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.

1 Like

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.

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.

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
1 Like

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 
} 
2 Likes

Cool but, 2 years later is this still the “official” way to list tags on an image?

2 Likes