docker

How can I list all tags for a Docker image on a remote registry?


How can I list all tags of a Docker image on a remote Docker registry using the CLI (preferred) or curl?

Preferably without pulling all versions from the remote registry. I just want to list the tags.


Solution

  • Update: Docker has deprecated the Docker Hub v1 API. To fetch tags using the v2 API, use e.g.

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

    Note: The results will be limited to the newest 100 tags. To get the next 100 tags, set the URL to https://.../tags?page_size=100&page=2 etc.

    For images other than Docker Official Images, replace library with the name of the user/organization.

    The URL https://hub.docker.com/v2/repositories/{namespace}/{repository}/tags also works at the moment, however it is unclear from the API specification whether it is legal.

    (If you have jq installed, you can replace the kludgy grep commands with jq -r '.results[].name'.)


    Original answer (v1 API, no long supported):

    I got the answer from here . Thanks a lot! :)

    Just one-line-script:(find all the tags of debian)

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

    UPDATE Thanks for @degelf's advice. Here is the shell script.

    #!/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/v1/repositories/${image}/tags -O -  | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | tr '}' '\n'  | awk -F: '{print $3}'`
    
    if [ -n "$2" ]
    then
        tags=` echo "${tags}" | grep "$2" `
    fi
    
    echo "${tags}"
    

    You can just create a new file name, dockertags, under /usr/local/bin (or add a PATH env to your .bashrc/.zshrc), and put that code in it. Then add the executable permissions(chmod +x dockertags).

    Usage:

    dockertags ubuntu ---> list all tags of ubuntu

    dockertags php apache ---> list all php tags php containing 'apache'