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

前端 未结 19 1884
时光取名叫无心
时光取名叫无心 2020-12-04 04:46

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 regi

19条回答
  •  有刺的猬
    2020-12-04 05:04

    You can also use this scrap :

    # vim /usr/sbin/docker-tags 
    

    & Append Following (as it is):

    #!/bin/bash
    im="$1"
    [[ -z "$im" ]] && { echo -e '\e[31m[-]\e[39m Where is the image name ??' ; exit ; }
    [[ -z "$(echo "$im"| grep -o '/')" ]] && { link="https://hub.docker.com/r/library/$im/tags/" ; } || { link="https://hub.docker.com/r/$im/tags/" ; }
    resp="$(curl -sL "$link")"
    err="$(echo "$resp" | grep -o 'Page Not Found')"
    if [[ ! -z "$err" ]] ; then
        echo -e "\e[31m[-]\e[39m No Image Found with name => [ \e[32m$im\e[39m ]"
        exit
    else
        tags="$(echo "$resp"|sed  -e 's|}|\n|g' -e 's|{|\n|g'|grep '"result"'|sed -e 's|,|\n|g'|cut -d '[' -f2|cut -d ']' -f1|sed  '/"tags":/d'|sed -e 's|"||g')"
        echo -e "\e[32m$tags\e[39m"
    fi
    

    Make it Executable :

    # chmod 755 /usr/sbin/docker-tags
    

    Then Finally Try By :

    $ docker-tags testexampleidontexist
       [-] No Image Found with name => [ testexampleidontexist ]
    
    $ docker search ubuntu
    
    $ docker-tags teamrock/ubuntu
       latest
    

    [ Hope you are aware of $ & # before running any command ]

提交回复
热议问题