How to list all tags for a Docker image on a remot

2019-01-29 19:45发布

I'd like to know how to list all tags of a Docker image on a remote Docker registry (tutum in our case but I don't suppose it matters) using the CLI (preferred) or curl? Preferably without pulling all versions from the remote registry, I just want to list the tags.

标签: docker
14条回答
萌系小妹纸
2楼-- · 2019-01-29 20:13

If you want to use the docker registry v2 API, it lists tags by pages. To list all the tags of an image, you may would like to add a large page_size parameter to the url, e.g.

curl -L -s 'https://registry.hub.docker.com/v2/repositories/library/centos/tags?page_size=1024'|jq '."results"[]["name"]'
查看更多
Lonely孤独者°
3楼-- · 2019-01-29 20:14

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 ]

查看更多
登录 后发表回答