Comprehensive Guide to Listing Docker Image Tags from Remote Registries

Nov 16, 2025 · Programming · 18 views · 7.8

Keywords: Docker | Image Tags | API Query | Shell Script | Pagination

Abstract: This article provides an in-depth exploration of methods for querying all tags of remote Docker images through command-line tools and API interfaces. It focuses on the usage of Docker Hub v2 API, including pagination mechanisms, parameter configuration, and result processing. The article details technical solutions using wget, curl combined with grep and jq for data extraction, and offers complete shell script implementations. It also discusses the advantages and limitations of different query approaches, providing practical technical references for developers and system administrators.

Overview of Remote Docker Image Tag Querying

In the Docker ecosystem, querying tag lists from remote image registries is a common and essential operation. With the deprecation of Docker Hub v1 API, developers need to transition to using v2 API for this functionality. This article provides detailed explanations of multiple query methods and their implementation specifics.

Docker Hub v2 API Query Methods

Docker has officially deprecated v1 API and recommends using v2 API for tag queries. The basic query URL format is: https://hub.docker.com/v2/namespaces/{namespace}/repositories/{repository}/tags. For official images, the namespace is library; for user or organization images, the namespace should be replaced with the corresponding username or organization name.

Command-Line Tool Implementation

Using wget combined with grep commands enables quick tag list retrieval:

wget -q -O - "https://hub.docker.com/v2/namespaces/library/repositories/debian/tags?page_size=100" | grep -o '"name": *"[^"]*' | grep -o '[^"]*$'

This command pipes the JSON response to grep for pattern matching, extracting tag names. Note that by default, the API returns the latest 100 tags; to retrieve more tags, pagination parameters are required.

Pagination Mechanism

Docker Hub API employs pagination for result returns. The page_size parameter controls the number of tags per page, while the page parameter specifies the page number. For example:

https://hub.docker.com/v2/namespaces/library/repositories/debian/tags?page_size=100&page=2

This design ensures efficient querying in large-scale image registries but requires developers to implement pagination logic to obtain complete tag lists.

JSON Processing Tool Optimization

Using the jq tool provides more elegant JSON response handling:

curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/centos/tags?page_size=1024' | jq '.results[].name'

jq offers powerful JSON parsing capabilities, accurately extracting required fields and avoiding complex string processing logic.

Complete Shell Script Implementation

Below is a fully functional shell script supporting tag querying and filtering:

#!/bin/bash

if [ $# -lt 1 ]
then
cat << HELP

dockertags  --  List all tags for a Docker image on a remote registry

EXAMPLE:
    - List all tags for ubuntu:
       dockertags ubuntu

    - List all php tags containing apache:
       dockertags php apache

HELP
fi

image="$1"
tags=`wget -q https://registry.hub.docker.com/v2/repositories/${image}/tags?page_size=100 -O - | jq -r '.results[].name'`

if [ -n "$2" ]
then
    tags=` echo "${tags}" | grep "$2" `
fi

echo "${tags}"

This script includes basic error checking and parameter validation, and can be configured for global system availability through environment variables.

Advanced Query Functionality

For scenarios requiring all tags, automatic pagination queries can be implemented:

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}))
    
    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
}

This function automatically calculates total page count, iterates through all pages to obtain complete tag lists, and outputs results in alphabetical order.

Alternative Tool Solutions

Beyond direct API usage, consider using the official hub-tool:

hub-tool tag ls bkuhl/game-watcher
hub-tool tag ls bkuhl/game-watcher --format json

hub-tool provides a more concise interface but is primarily suitable for Docker Hub; other private registries still require API-based solutions.

Technical Summary

When implementing remote Docker image tag queries, several key aspects require attention: API version compatibility, pagination handling mechanisms, JSON response parsing, and error handling logic. Selecting appropriate tools and methods can significantly improve query efficiency and code maintainability.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.