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条回答
Emotional °昔
2楼-- · 2019-01-29 19:50

I've managed to get it working using curl:

curl -u <username>:<password> https://tutum.co/v1/repositories/<username>/<image_name>/tags

Note that image_name should not contain user details etc. For example if you're pushing image named tutum.co/username/x then image_name should be x.

查看更多
你好瞎i
3楼-- · 2019-01-29 19:50

The Docker V2 API requires an OAuth bearer token with the appropriate claims. In my opinion, the official documentation is rather vague on the topic. So that others don't go through the same pain I did, I offer the below docker-tags function.

The most recent version of docker-tags can be found in my GitHubGist : "List Docker Image Tags using bash".

The docker-tags function has a dependency on jq. If you're playing with JSON, you likely already have it.

#!/usr/bin/env bash
docker-tags() {
    arr=("$@")

    for item in "${arr[@]}";
    do
        tokenUri="https://auth.docker.io/token"
        data=("service=registry.docker.io" "scope=repository:$item:pull")
        token="$(curl --silent --get --data-urlencode ${data[0]} --data-urlencode ${data[1]} $tokenUri | jq --raw-output '.token')"
        listUri="https://registry-1.docker.io/v2/$item/tags/list"
        authz="Authorization: Bearer $token"
        result="$(curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $token" $listUri | jq --raw-output '.')"
        echo $result
    done
}

Example

docker-tags "microsoft/nanoserver" "microsoft/dotnet" "library/mongo" "library/redis"

Admittedly, docker-tags makes several assumptions. Specifically, the OAuth request parameters are mostly hard coded. A more ambitious implementation would make an unauthenticated request to the registry and derive the OAuth parameters from the unauthenticated response.

查看更多
叼着烟拽天下
4楼-- · 2019-01-29 19:51

Building on Yan Foto's answer (the v2 api), I created a simple Python script to list the tags for a given image.

Usage:

./docker-registry-list.py alpine

Output:

{
  "name": "library/alpine",
  "tags": [
    "2.6",
    "2.7",
    "3.1",
    "3.2",
    "3.3",
    "3.4",
    "3.5",
    "3.6",
    "3.7",
    "edge",
    "latest"
  ]
}
查看更多
Anthone
5楼-- · 2019-01-29 19:52

If the JSON parsing tool, jq is available

wget -q https://registry.hub.docker.com/v1/repositories/debian/tags -O - | \
    jq -r .[].name
查看更多
Summer. ? 凉城
6楼-- · 2019-01-29 19:54

See CLI utility: https://www.npmjs.com/package/docker-browse

Allows enumeration of tags and images.

docker-browse tags <image> will list all tags for the image. e.g. docker-browse tags library/alpine

docker-browse images will list all images in the registry. Not currently available for index.docker.io.

You may connect it to any registry, including your private one, so long as it supports Docker Registry HTTP API V2

查看更多
不美不萌又怎样
7楼-- · 2019-01-29 19:55
curl -u <username>:<password> https://$your_registry/v2/$image_name/tags/list -s -o - | \
    tr -d '{' | tr -d '}' | sed -e 's/[][]//g' -e 's/"//g' -e 's/ //g' | \
    awk -F: '{print $3}' | sed -e 's/,/\n/g'

You can use it if your env has no 'jq', = )

查看更多
登录 后发表回答