【问题标题】:Retrieve Docker image tags from a 3rd party repo从第 3 方存储库中检索 Docker 映像标签
【发布时间】:2019-05-09 00:51:39
【问题描述】:

对于直接来自 Docker Hub 的 Docker 映像,我可以通过访问其存储库 API 来检索映像的当前标签列表。例如,https://registry.hub.docker.com/v1/repositories/python/tags 会给我一个可以与docker pull python:<tag> 一起使用的标签列表。

对于 Elastic Search,我使用的是他们的官方存储库,并且可以使用 docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.0 之类的方式提取图像

但是,我不知道如何从该存储库中提取标签列表。我试过了

https://docker.elastic.co/elasticsearch/elasticsearch/tags
https://docker.elastic.co/v1/repositories/elasticsearch
https://docker.elastic.co/v2/repositories/elasticsearch/elasticsearch/_manifests/tags

..以及其他几个变体。 docker 命令行工具在后端请求中将该存储库/映像名称转换为哪些 URL/API 端点?

【问题讨论】:

    标签: docker docker-registry docker-api


    【解决方案1】:

    原来docker.elastic.co 正在运行一个 V2 docker 注册表,因此它需要 V2 API 命令和令牌身份验证。尝试最初获取标签会导致 401,其中包含有关如何获取令牌的信息:

    http https://docker.elastic.co/v2/elasticsearch/elasticsearch/tags/list                                                                                                                       (566ms)  
    HTTP/1.1 401 Unauthorized
    Connection: keep-alive
    Content-Length: 170
    Content-Type: application/json; charset=utf-8
    Date: Thu, 09 May 2019 15:24:42 GMT
    Docker-Distribution-Api-Version: registry/2.0
    Www-Authenticate: Bearer realm="https://docker-auth.elastic.co/auth",service="token-service",scope="repository:elasticsearch/elasticsearch:pull"
    X-Content-Type-Options: nosniff
    
    {
        "errors": [
            {
                "code": "UNAUTHORIZED",
                "detail": [
                    {
                        "Action": "pull",
                        "Class": "",
                        "Name": "elasticsearch/elasticsearch",
                        "Type": "repository"
                    }
                ],
                "message": "authentication required"
            }
        ]
    }
    

    使用WWW-Authenticate 中的信息为给定的servicescope 请求令牌:

    http "https://docker-auth.elastic.co/auth?service=token-service&scope=repository:elasticsearch/elasticsearch:pull"                                                                            (567ms)  
    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 790
    Content-Type: application/json
    Date: Thu, 09 May 2019 15:25:37 GMT
    
    {
        "token": "some-long-token"
    }
    

    最后,使用令牌发出请求:

    http -v https://docker.elastic.co/v2/elasticsearch/elasticsearch/tags/list 'Authorization: Bearer some-long-token'
    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Length: 1765
    Content-Type: application/json; charset=utf-8
    Date: Thu, 09 May 2019 15:26:18 GMT
    Docker-Distribution-Api-Version: registry/2.0
    X-Content-Type-Options: nosniff
    
    {
        "name": "elasticsearch/elasticsearch",
        "tags": [
            "5.0.0-731e78df",
            "5.0.0-86a0b164",
            "5.0.0-alpha5",
            "5.0.0-beta1",
            "5.0.0-ccd69424",
            "5.0.0-rc1",
            "5.0.0",
            ...
            ...
            ...
    

    【讨论】:

      【解决方案2】:

      您可以尝试使用与 python 相同的方式来获取可用版本的标签/列表。

      示例:https://registry.hub.docker.com/v1/repositories/elasticsearch/tags

      样本输出:[{"layer": "", "name": "1"}, {"layer": "", "name": "1-alpine"}]

      因此,您将尝试在 shell 脚本中提供/显示标签列表并要求他们选择。然后基于此,您将执行 docker pull 并在您的自定义 Docker 文件中运行这些命令?

      【讨论】:

      • 这不是同一个存储库。当您从 docker.elastic.co 拉取数据时,它使用的是 docker.elastic.co,而不是 hub.docker.com。
      • 我想通了。见我上面的回答。
      • 很高兴听到这个消息,因为只有我提到了从 docker hub 拉取图像列表的建议。因为他们一直在镜像那些与弹性相关的图像(不要认为所有弹性 docker 图像 :))。参考:github.com/elastic/elasticsearch-docker/issues/89
      猜你喜欢
      • 2018-12-28
      • 2018-11-28
      • 2018-01-05
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多