【问题标题】:How to get manifests using HTTP API v2?如何使用 HTTP API v2 获取清单?
【发布时间】:2019-08-11 15:33:33
【问题描述】:

How to authenticate with the V2 API 有用且有效。

REPO="https://hub.docker.com/v2"

我能够获取令牌、列出(我的)存储库并列出它们的图像和标签。

curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/

curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/tags/

我想“获取清单”,但我很难让它发挥作用: https://docs.docker.com/registry/spec/api/#manifest:

curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/manifests/

curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/${USERNAME}/${IMAGE}/manifests/

curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/${USERNAME}/${IMAGE}/manifests/${TAG}

我试过不带Host 标头。带有 Host 标头的各种值。但是,我显然错过了一些东西。我尝试对工作端点进行模式匹配,但没有任何乐趣:

curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/manifests/

奇怪的是,此页面显示的“GET TAGS”似乎错误地显示为/v2/<name>/tags/listhttps://docs.docker.com/registry/spec/api/#tags

评论: https://stackoverflow.com/a/45605443/609290

跟进

我是 Google 员工,可以访问 Google Container Registry (GCR)。

REPO="https://gcr.io/v2/"

一时兴起,我刚刚尝试了针对 GCR 的“GET MANIFEST”并且请求有效:

curl --silent \
--request GET \
--user _token:$(gcloud auth print-access-token) \
${REPO}/${PROJECT}/${IMAGE}/manifests/${TAG}

【问题讨论】:

    标签: docker-registry


    【解决方案1】:

    所有*.docker.com|io 子域都令人困惑!
    我发现registry.hub.docker.comindex.docker.io 是最可靠的。

    您可以轻松地从那里查询标签,但对于清单,您需要先获取一个令牌:

    
    REGISTRY=https://index.docker.io/v2
    #REGISTRY="https://registry.hub.docker.com/v2"
    #REGISTRY="https://registry.docker.io/v2"
    #REGISTRY="https://registry-1.docker.io/v2"
    #REGISTRY="https://hub.docker.com/v2"
    
    REPO=library
    IMAGE=debian
    # Could also be a repo digest
    TAG=latest
    
    # Query tags
    curl "$REGISTRY/repositories/$REPO/$IMAGE/tags/"
    
    # Query manifest
    curl -iL "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
    # HTTP/1.1 401 Unauthorized
    # Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/debian:pull"
    
    TOKEN=$(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" \
      | jq --raw-output .token)
    curl -LH "Authorization: Bearer ${TOKEN}" "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
    
    # Some repos seem to return V1 Schemas by default
    
    REPO=nginxinc
    IMAGE=nginx-unprivileged 
    TAG=1.17.2
    
    curl -LH "Authorization: Bearer $(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" | jq --raw-output .token)" \
     "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
    
    # Solution: Set the Accept Header for V2
    
    curl -LH "Authorization: Bearer $(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" | jq --raw-output .token)" \
      -H "Accept:application/vnd.docker.distribution.manifest.v2+json" \
     "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
    

    hub.docker.comworks differently 的授权,您似乎没有从那里获得清单 ?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 2022-12-11
    • 2021-05-09
    • 1970-01-01
    • 2020-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多