What is the canonical way to see if an image exists in the public docker registry?

We want to check if the image exists in the shared registry (Docker Hub) before we begin the deployment. With API v1, we simply request https://index.docker.io/v1/repositories/gliderlabs/alpine/tags/3.2 , for example.

But now the official registry API is v2, what is the official way to check for an image in the public registry?

v1

 $ curl -i https://index.docker.io/v1/repositories/gliderlabs/alpine/tags/latest HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Tue, 11 Aug 2015 10:02:09 GMT Content-Type: application/json Transfer-Encoding: chunked Vary: Cookie X-Frame-Options: SAMEORIGIN Strict-Transport-Security: max-age=31536000 [{"pk": 20307475, "id": "5bd56d81"}, {"pk": 20355979, "id": "511136ea"}] 

v2

 $ curl -i https://index.docker.io/v2/repositories/gliderlabs/alpine/tags/latest HTTP/1.1 301 MOVED PERMANENTLY Server: nginx/1.6.2 Date: Tue, 11 Aug 2015 10:04:20 GMT Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked X-Frame-Options: SAMEORIGIN Location: https://index.docker.io/v2/repositories/gliderlabs/alpine/tags/latest/ Strict-Transport-Security: max-age=31536000 $ curl -i https://index.docker.io/v2/repositories/gliderlabs/alpine/tags/latest/ HTTP/1.1 301 MOVED PERMANENTLY Server: nginx/1.6.2 Date: Tue, 11 Aug 2015 10:04:26 GMT Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked X-Frame-Options: SAMEORIGIN Location: https://registry.hub.docker.com/v2/repositories/gliderlabs/alpine/tags/latest/ Strict-Transport-Security: max-age=31536000 $ curl -i https://registry.hub.docker.com/v2/repositories/gliderlabs/alpine/tags/latest/ HTTP/1.1 200 OK Server: nginx/1.6.2 Date: Tue, 11 Aug 2015 10:04:34 GMT Content-Type: application/json Transfer-Encoding: chunked Vary: Cookie X-Frame-Options: SAMEORIGIN Allow: GET, DELETE, HEAD, OPTIONS Strict-Transport-Security: max-age=31536000 {"name": "latest", "full_size": 5250074, "id": 130839, "repository": 127805, "creator": 152141, "last_updater": 152141, "image_id": null, "v2": false} 

Should I stick to URL v1 , although now it is deprecated or uses URL v2 , but there is no documentation about this? If I use v2 , should I use https://registry.hub.docker.com/v2/ directly or use https://index.docker.io/v1/ and follow the redirects?

+8
docker docker-registry dockerhub
source share
1 answer

The upstream download-frozen-image-v2.sh script should be used as at least a decent example of the API here ( https://github.com/docker/docker/blob/6bf8844f1179108b9fabd271a655bf9eaaf1ee8c/contrib/download-frozen-image-v2.sh# L47-L54 ).

The main key is that you will need to press registry-1.docker.io instead of index.docker.io , and you will need the β€œtoken” from auth.docker.io ( https://auth.docker.io/token? service = registry.docker.io & scope = repository: gliderlabs / alpine: pull ), even if you just request read-only access to the public repository. After you receive this token, you can click https://registry-1.docker.io/v2/gliderlabs/alpine/manifests/latest with the Authorization header, which will either return the JSON manifest of the image or an error using 404.

 token="$(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output .token)" curl -fsSL -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$image/manifests/$digest" 
+1
source share

All Articles