How can I find a Docker image with a specific tag in Docker registry on the Docker command line?

前端 未结 10 1210
小蘑菇
小蘑菇 2020-12-12 18:21

I try to locate one specific tag for a Docker image. How can I do it on the command line? I want to avoid downloading all the images and then removing the unneeded ones.

10条回答
  •  臣服心动
    2020-12-12 18:46

    This script (docker-show-repo-tags.sh) should work for any Docker enabled host that has curl, sed, grep, and sort. This was updated to reflect the fact the repository tag URLs changed.

    #!/bin/sh
    #
    # Simple script that will display Docker repository tags
    # using basic tools: curl, sed, grep, and sort.
    #
    # Usage:
    #   $ docker-show-repo-tags.sh ubuntu centos
    for Repo in $* ; do
        curl -sS "https://hub.docker.com/r/library/$Repo/tags/" | \
            sed -e $'s/"tags":/\\\n"tags":/g' -e $'s/\]/\\\n\]/g' | \
            grep '^"tags"' | \
            grep '"library"' | \
            sed -e $'s/,/,\\\n/g' -e 's/,//g' -e 's/"//g' | \
            grep -v 'library:' | \
            sort -fu | \
            sed -e "s/^/${Repo}:/"
    done
    

    This older version no longer works.

    #!/bin/sh
    # WARNING: This no long works!
    # Simple script that will display Docker repository tags.
    #
    # Usage:
    #   $ docker-show-repo-tags.sh ubuntu centos
    for Repo in $* ; do
      curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$Repo/tags/" | \
        sed -e $'s/,/,\\\n/g' -e $'s/\[/\\\[\n/g' | \
        grep '"name"' | \
        awk -F\" '{print $4;}' | \
        sort -fu | \
        sed -e "s/^/${Repo}:/"
    done
    

    This is the output for a simple example:

    $ docker-show-repo-tags.sh centos | cat -n
         1    centos:5
         2    centos:5.11
         3    centos:6
         4    centos:6.10
         5    centos:6.6
         6    centos:6.7
         7    centos:6.8
         8    centos:6.9
         9    centos:7.0.1406
        10    centos:7.1.1503
        11    centos:7.2.1511
        12    centos:7.3.1611
        13    centos:7.4.1708
        14    centos:7.5.1804
        15    centos:centos5
        16    centos:centos5.11
        17    centos:centos6
        18    centos:centos6.10
        19    centos:centos6.6
        20    centos:centos6.7
        21    centos:centos6.8
        22    centos:centos6.9
        23    centos:centos7
        24    centos:centos7.0.1406
        25    centos:centos7.1.1503
        26    centos:centos7.2.1511
        27    centos:centos7.3.1611
        28    centos:centos7.4.1708
        29    centos:centos7.5.1804
        30    centos:latest
    

提交回复
热议问题