How to get manifests using HTTP API v2?

前端 未结 1 1519
名媛妹妹
名媛妹妹 2021-01-13 15:13

How to authenticate with the V2 API is useful and works.

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

I\'m abl

相关标签:
1条回答
  • 2021-01-13 15:58

    It's quite confusing with all the *.docker.com|io subdomains!
    I found registry.hub.docker.com and index.docker.io the most reliable ones.

    You can easily query the tags from there, but for the manifests you'll need to get a token for pulling first:

    
    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"
    

    See

    • this gist for another example and
    • this repo for a reusable script docker-image-size-curl.sh

    Authorization with hub.docker.com works differently and you don't seem to get the manifests from there

    0 讨论(0)
提交回复
热议问题