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 19:57

Get all tags from Docker Hub: this command uses the command-line JSON processor jq to select the tag names from the JSON returned by the Docker Hub Registry (the quotes are removed with tr). Replace library with the Docker Hub user name, debian with the image name:

curl -s 'https://registry.hub.docker.com/v2/repositories/library/debian/tags/' | jq -r '."results"[]["name"]'
查看更多
【Aperson】
3楼-- · 2019-01-29 19:58

I have done this thing when I have to implement a task in which if user somehow type the wrong tag then we have to give the list of all the tag present in the repo(Docker repo) present in the register. So I have code in batch Script.

<html>
<pre style="background-color:#bcbbbb;">
@echo off

docker login --username=xxxx --password=xxxx
docker pull %1:%2

IF NOT %ERRORLEVEL%==0 (
echo "Specified Version is Not Found "
echo "Available Version for this image is :"
for /f %%i in (' curl -s -H "Content-Type:application/json" -X POST -d "{\"username\":\"user\",\"password\":\"password\"}" https://hub.docker.com/v2/users/login ^|jq -r .token ') do set TOKEN=%%i
curl -sH "Authorization: JWT %TOKEN%" "https://hub.docker.com/v2/repositories/%1/tags/" | jq .results[].name
)
</pre>
</html>

So in this we can give arguments to out batch file like:

Dockerfile java version7 

查看更多
放荡不羁爱自由
4楼-- · 2019-01-29 20:08

As of Docker Registry V2, a simple GET suffice:

GET /v2/<name>/tags/list

See docs for more.

查看更多
三岁会撩人
5楼-- · 2019-01-29 20:11

The Docker Registry API has an endpoint to list all tags.

Looks like Tutum has a similar endpoint, as well as a way to access via tutum-cli.

With the tutum-cli, try the following:

tutum tag list <uuid>
查看更多
Fickle 薄情
6楼-- · 2019-01-29 20:12

Here's a Powershell script I wrote for Windows. Handles v1 and v2 repos:

Get-DockerImageVersions.ps1:

param (
  [Parameter (Mandatory=$true)]$ImageName,
  [Parameter (Mandatory=$false)]$RegistryURL
)

if (!$RegistryURL) 
{
  $RegistryURL = "https://registry.hub.docker.com/v1/repositories"
}

$list = ""
if ($RegistryURL -like "*v2*") 
{
  $list = "/list"
}

$URL = "$RegistryURL/$ImageName/tags$list"

write-debug $URL
$resp = Invoke-WebRequest -UseBasicParsing $URL | ConvertFrom-Json

if ($RegistryURL -like "*v2*") 
{
  $tags = $resp | select tags
  $tags.tags
} else {
  $tags = $resp | select name
  $tags.name
}
查看更多
家丑人穷心不美
7楼-- · 2019-01-29 20:13

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'

查看更多
登录 后发表回答