Can I get an image digest without downloading the image?

前端 未结 6 443
执念已碎
执念已碎 2021-02-01 09:00

Similar to the question \"What´s the sha256 code of a docker image?\", I would like to find the digest of a Docker image. I can see the digest when I download an image:

6条回答
  •  深忆病人
    2021-02-01 09:34

    For newer versions of Docker, the inspect command provides the correct value:

    docker inspect --format='{{index .RepoDigests 0}}' waisbrot/wait
    

    For older versions, fetch the value from the repository following this example with the main Docker repo:

    curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
         -H "Authorization: Basic ${username_password_base64}" \
         'https://auth.docker.io/token?service=registry.docker.io&scope=repository:waisbrot/wait:pull' 
    

    Naive attempts to fetch that value fail because the default content-type being selected by the server is application/vnd.docker.distribution.manifest.v1+prettyjws (a v1 manifest) and you need to v2 manifest. Therefore, you need to set the Accept header to application/vnd.docker.distribution.manifest.v2+json.

提交回复
热议问题