获取可从命令行提取的 docker 标签列表?

Get list of docker tags available to pull from command line?

我想获取有关已发布 versions/tags 的 docker 图像的一些基本信息,以了解我可以提取哪些 image:tag。我还想看看每个标签最近发布的时间。

有没有办法在命令行上执行此操作?

Docker version 1.10.2, build c3959b1

基本上是为 docker 图像寻找 npm info {pkg} 的等价物。

不是来自命令行。你有 docker search 但它只是 returns 你想要的数据的一个子集,并且只针对带有 :latest 标签的图像:

> docker search sixeyed/hadoop-dotnet
NAME                    DESCRIPTION                        STARS     OFFICIAL   AUTOMATED
sixeyed/hadoop-dotnet   Hadoop with .NET Core installed    1                    [OK]

如果您需要更多详细信息,您需要使用 registry API, but it only has a catalog endpoint for listing repositories, the issue for search 仍然开放。

假设您知道存储库名称,您可以导航 API - 首先您需要一个身份验证令牌:

> curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:sixeyed/hadoop-dotnet:pull"
{"token":"eyJhbG...

然后将令牌传递给后续请求,例如列出标签:

> curl --header "Authorization: Bearer eyJh..." https://index.docker.io/v2/sixeyed/hadoop-dotnet/tags/list
{"name":"sixeyed/hadoop-dotnet","tags":["2.7.2","latest"]} 

然后通过存储库名称和标签获取一张图片的所有信息:

> curl --header "Authorization: Bearer eyJh..." https://index.docker.io/v2/sixeyed/hadoop-dotnet/manifests/latest

如果您不想使用令牌:

curl -L -s 'https://registry.hub.docker.com/v2/repositories/<$repo_name>/tags?page=<$page_nb>&page_size=<$page_size>' | jq '."results"[]["name"]'

在哪里可以获得 <$repo_name>

docker search <$expression>

例如:

$ docker search piwigo
NAME                        DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
linuxserver/piwigo          A Piwigo container, brought to you by LinuxS…   152                  
mathieuruellan/piwigo       Easy deployment of piwigo for my personal us…   19                   [OK]
lsioarmhf/piwigo                                                            3                    
hg8496/piwigo                                                               2                    [OK]
[…]

$ curl -L -s 'https://registry.hub.docker.com/v2/repositories/linuxserver/piwigo/tags?page=1&page_size=10' | jq '."results"[]["name"]'
"latest"
"12.0.0"
"version-12.0.0"
"12.0.0-ls137"
"arm64v8-12.0.0"
"arm32v7-12.0.0"
"amd64-12.0.0"
"arm64v8-version-12.0.0"
"arm32v7-version-12.0.0"
"amd64-version-12.0.0"

来源:Démarrer avec les containers Docker

I want to get some basic information about the published versions/tags of a docker image, to know what image:tag's I can pull.

这是来自 tags/list API。这是一个执行此操作的小脚本:

#!/bin/sh

ref="${1:-library/ubuntu:latest}"
repo="${ref%:*}"
tag="${ref##*:}"
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
        | jq -r '.token')
curl -H "Authorization: Bearer $token" \
     -s "https://registry-1.docker.io/v2/${repo}/tags/list" | jq .

运行 看起来像:

$ ./tags-v2.sh library/ubuntu:latest
{                                   
  "name": "library/ubuntu",         
  "tags": [                         
    "10.04",                        
    "12.04",                        
    "12.04.5",                      
    "12.10",                        
    "13.04",                        
    "13.10",                        
    "14.04",                        
    "14.04.1",      
...

I would also like to see the time that each tag was most recently published.

您可能想为此拉 image config。首先,您需要拉取清单,解析配置描述符,然后为配置拉取该 blob json。这是一个脚本,可以为 docker 个图像执行此操作:

#!/bin/sh

ref="${1:-library/ubuntu:latest}"
repo="${ref%:*}"
tag="${ref##*:}"
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull" \
        | jq -r '.token')
digest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
              -H "Authorization: Bearer $token" \
              -s "https://registry-1.docker.io/v2/${repo}/manifests/${tag}" \
         | jq -r .config.digest)
curl -H "Accept: application/vnd.docker.container.image.v1+json" \
     -H "Authorization: Bearer $token" \
     -s -L "https://registry-1.docker.io/v2/${repo}/blobs/${digest}" | jq .

以及 运行 该脚本的示例:

$ ./get-config-v2.sh library/ubuntu:latest
{
  "architecture": "amd64",
  "config": {
    "Hostname": "",
    "Domainname": "",
    "User": "",
    "AttachStdin": false,
    "AttachStdout": false,
    "AttachStderr": false,
    "Tty": false,
    "OpenStdin": false,
    "StdinOnce": false,
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Cmd": [
      "bash"
    ],
    "Image": "sha256:6c18a628d47eacf574eb93da2324293a0e6c845084cca2ea13efaa3cee4d0799",
    "Volumes": null,
    "WorkingDir": "",
    "Entrypoint": null,
    "OnBuild": null,
    "Labels": null
  },
  "container": "249e88be79ad9986a479c71c15a056946ae26b0c54c1f634f115be6d5f9ba1c8",
  "container_config": {
    "Hostname": "249e88be79ad",
    "Domainname": "",
    "User": "",
    "AttachStdin": false,
    "AttachStdout": false,
    "AttachStderr": false,
    "Tty": false,
    "OpenStdin": false,
    "StdinOnce": false,
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Cmd": [
      "/bin/sh",
      "-c",
      "#(nop) ",
      "CMD [\"bash\"]"
    ],
    "Image": "sha256:6c18a628d47eacf574eb93da2324293a0e6c845084cca2ea13efaa3cee4d0799",
    "Volumes": null,
    "WorkingDir": "",
    "Entrypoint": null,
    "OnBuild": null,
    "Labels": {}
  },
  "created": "2021-10-16T00:37:47.578710012Z",
  "docker_version": "20.10.7",
  "history": [
    {
      "created": "2021-10-16T00:37:47.226745473Z",
      "created_by": "/bin/sh -c #(nop) ADD file:5d68d27cc15a80653c93d3a0b262a28112d47a46326ff5fc2dfbf7fa3b9a0ce8 in / "
    },
    {
      "created": "2021-10-16T00:37:47.578710012Z",
      "created_by": "/bin/sh -c #(nop)  CMD [\"bash\"]",
      "empty_layer": true
    }
  ],
  "os": "linux",
  "rootfs": {
    "type": "layers",
    "diff_ids": [
      "sha256:9f54eef412758095c8079ac465d494a2872e02e90bf1fb5f12a1641c0d1bb78b"
    ]
  }
}

请注意,这只会为您提供来自构建工具的详细信息,注册表本身不会跟踪图像从任何 OCI API 上传到该注册表的时间(某些注册表可能会添加自己的元数据,但这将是注册表具体)。


为了处理更多的身份验证类型、不同种类的图像(OCI vs Docker)以及类似的,我将这些命令和更多内容打包到 regclient project 中的 regctl 中。 Google 的容器注册表 crane 命令和 RedHat 的 skopeo 中存在类似的项目,每个都允许从命令行访问注册表:

$ regctl tag ls ubuntu
10.04           
12.04           
12.04.5         
12.10           
13.04           
13.10           
14.04           
14.04.1         
14.04.2         
14.04.3         
14.04.4         
14.04.5      
...

$ regctl image config ubuntu
{
  "created": "2021-10-16T00:37:47.578710012Z",
  "architecture": "amd64",
  "os": "linux",
  "config": {
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
    ],
    "Cmd": [
      "bash"
    ]
  },
  "rootfs": {
    "type": "layers",
    "diff_ids": [
      "sha256:9f54eef412758095c8079ac465d494a2872e02e90bf1fb5f12a1641c0d1bb78b"
    ]
  },
  "history": [
    {
      "created": "2021-10-16T00:37:47.226745473Z",
      "created_by": "/bin/sh -c #(nop) ADD file:5d68d27cc15a80653c93d3a0b262a28112d47a46326ff5fc2dfbf7fa3b9a0ce8 in / "
    },
    {
      "created": "2021-10-16T00:37:47.578710012Z",
      "created_by": "/bin/sh -c #(nop)  CMD [\"bash\"]",
      "empty_layer": true
    }
  ]
}