dockerdockerhub

Dockerhub: listing all available versions of a given image?


I'm looking for a way to list all publicly available versions of an image from Dockerhub. Is there a way this could be achieved?

Specifically, I'm interested in the openjdk:8-jdk-alpine images.

Dockerhub typically only lists the latest version of each image, and there are no linking to historic versions. For openjdk, it's currently 8u191-jdk-alpine3.8:

Dockerhub openjdk alpine

However, it possible to pull older versions if we know their image digest ID:

openjdk:8-jdk-alpine@sha256:1fd5a77d82536c88486e526da26ae79b6cd8a14006eb3da3a25eb8d2d682ccd6
openjdk:8-jdk-alpine@sha256:c5c705b462abab858066d412b3f871865684d8f837571c98b68e78c505dc7549

With some luck, I was able to find these digests for OpenJDK 8 (Java versions 1.8.0_171 and 1.8.0_151 respectively), by googling openjdk8 alpine digest and looking at github tickets, which included the image digest.

But, is there a systematic way for listing all publicly available digests?

Looking at docker search documentation, there's doesn't seem to be an option for listing the image version, only search by name.


Solution

  • You don't need digests to pull "old" images, you would rather use their tags (even if they are not displayed in Docker Hub).

    EDIT (2023/10/01): with Docker Hub v2 API, because v1 has been deprecated

    Docker Hub v1 API has been deprecated on 2022/09/05, so we now need to use the v2 API.

    Use the following command to retrieve tags of a particular image, parsing the output of https://registry.hub.docker.com/v2/namespaces/$REGISTRY/repositories/$REPOSITORY/tags. You also need jq installed to parse JSON result:

    # for official images, REGISTRY is library and REPOSITORY is the name of the image
    # otherwise, split the image name (e.g. google/cloud-sdk into REGISTRY=google and REPOSITORY=cloud-sdk)
    REGISTRY=library
    REPOSITORY=openjdk
    
    next_page="https://registry.hub.docker.com/v2/namespaces/$REGISTRY/repositories/$REPOSITORY/tags?page=1&page_size=1000"
    
    while [ "$next_page" != "null" ]
    do
        result=$(curl -s "$next_page")
        echo $result | jq -r '.results[].name'
        
        next_page=$(echo $result | jq -r '.next')
    done
    

    Unlike with v1 API, we need to paginate here (so we use the next_page value to get all results).

    You can then filter and only keep tags you're interested in, with | jq 'select(match("^19.*jdk-alpine"))' or | grep -E '^19.*jdk-alpine'.

    Result for REGISTRY=library REPOSITORY=openjdk (11812 tags at the time of writing) looks like:

    22-slim-bullseye
    22-slim-bookworm
    22-slim
    22-oraclelinux8
    22-oraclelinux7
    22-oracle
    22-jdk-slim-bullseye
    22-jdk-slim-bookworm
    22-jdk-slim
    22-jdk-oraclelinux8
    [...]
    

    Old answer using Docker Hub v1 API (won't work anymore, API is now deprecated)

    I use the following command to retrieve tags of a particular image, parsing the output of https://registry.hub.docker.com/v1/repositories/$REPOSITORY/tags :

    REPOSITORY=openjdk # can be "<registry>/<image_name>" ("google/cloud-sdk" for example)
    wget -q https://registry.hub.docker.com/v1/repositories/$REPOSITORY/tags -O - | \
        jq -r '.[].name'
    

    Result for REPOSITORY=openjdk (1593 tags at the time of writing) looks like :

    latest
    10
    10-ea
    10-ea-32
    10-ea-32-experimental
    10-ea-32-jdk
    10-ea-32-jdk-experimental
    10-ea-32-jdk-slim
    10-ea-32-jdk-slim-experimental
    10-ea-32-jre
    [...]
    

    If you can't/don't want to install jq (tool to manipulate JSON), then you could use :

    wget -q https://registry.hub.docker.com/v1/repositories/$REPOSITORY/tags -O - | \
        sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | \
        tr '}' '\n'  | \
        awk -F: '{print $3}'
    

    (I'm pretty sure I got this command from another question, but I can't find where)

    You can of course filter the output of this command and keep only tags you're interested in :

    wget -q https://registry.hub.docker.com/v1/repositories/$REPOSITORY/tags -O - | \
        jq -r '.[].name | select(match("^8.*jdk-alpine"))'
    

    or :

    wget -q https://registry.hub.docker.com/v1/repositories/$REPOSITORY/tags -O - | \
        jq -r '.[].name' \
        grep -E '^8.*jdk-alpine'