Is it possible to get image id from Docker Registry V2?

When the image was transferred to the V2 registry, will the image identifier also be transferred to the registry? Is it possible to get the image id for a specific repository from the V2 registry?

+1
docker docker-registry docker-image
source share
3 answers

If the image was clicked using Docker Client 1.10 or higher, you can get the image identifier from the registry using

GET /v2/<image>/manifests/<tag> 

Your request must contain a title

 Accept: application/vnd.docker.distribution.manifest.v2+json 

In the response, the image identifier will be in the header of the Content-Docker-Digest response.

+4
source share

From my research you can get the image id from the registry (2.3.0+) using

curl -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' http://$server/v2/$repo/manifests/$tag

and the config.digest field in the response represents imageID what you want!

eg

applies: https://duyanghao.imtqy.com/docker-registry-pull-manifest-v2/

+4
source share

As far as I can tell, they are not stored in any available api location:

 bash$ docker run -d -p 5000:5000 --restart=always --name registry registry:2 Unable to find image 'registry:2' locally 2: Pulling from library/registry ... bash$ docker tag busybox localhost:5000/busybox bash$ docker push localhost:5000/busybox The push refers to a repository [localhost:5000/busybox] 5f70bf18a086: Pushed ... bash$ curl http://localhost:5000/v2/busybox/tags/list {"name":"busybox","tags":["latest"]} bash$ curl http://localhost:5000/v2/busybox/manifests/latest { "schemaVersion": 1, "name": "busybox", "tag": "latest", "architecture": "amd64", "fsLayers": [ { "blobSum": "sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4" }, { "blobSum": "sha256:385e281300cc6d88bdd155e0931fbdfbb1801c2b0265340a40481ee2b733ae66" } ], "history": [ { "v1Compatibility": "{\"architecture\":\"amd64\",\"config\":{\"Hostname\":\"156e10b83429\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"sh\"],\"Image\":\"56ed16bd6310cca65920c653a9bb22de6b235990dcaa1742ff839867aed730e5\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":{}},\"container\":\"5f8098ec29947b5bea80483cd3275008911ce87438fed628e34ec0c522665510\",\"container_config\":{\"Hostname\":\"156e10b83429\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":null,\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) CMD [\\\"sh\\\"]\"],\"Image\":\"56ed16bd6310cca65920c653a9bb22de6b235990dcaa1742ff839867aed730e5\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":{}},\"created\":\"2016-03-18T18:22:48.810791943Z\",\"docker_version\":\"1.9.1\",\"id\":\"437595becdebaaaf3a4fc3db02c59a980f955dee825c153308c670610bb694e1\",\"os\":\"linux\",\"parent\":\"920777304d1d5e337bc59877253e946f224df5aae64c72538672eb74637b3c9e\"}" }, { "v1Compatibility": "{\"id\":\"920777304d1d5e337bc59877253e946f224df5aae64c72538672eb74637b3c9e\",\"created\":\"2016-03-18T18:22:48.262403239Z\",\"container_config\":{\"Cmd\":[\"/bin/sh -c #(nop) ADD file:47ca6e777c36a4cfffe3f918b64a445c8f32300deeb9dfa5cc47261bd7b75d21 in /\"]}}" } ], "signatures": [ { "header": { "jwk": { "crv": "P-256", "kid": "FIFX:SJRD:AQHW:MCFX:M6WC:LXI2:3VO2:4LFW:UHDZ:QUN7:OLX4:6WGD", "kty": "EC", "x": "Xm8wJTzw3nb--rGoD3dxjKffikj7Snb9dHW-qGbqSAM", "y": "GnATS--7lVcA_-jQGuDKTtjhmnGgvBrx8rLdlPOJV3U" }, "alg": "ES256" }, "signature": "f8NVzOF6ujm_0COedniGCGL_q3KsTfKFM9T8ZZDf2MSIMJ3TYoR_s795NqdEy8yWaoLuT2LoI0BCEsuOTZUhCw", "protected": "eyJmb3JtYXRMZW5ndGgiOjE5MTQsImZvcm1hdFRhaWwiOiJDbjAiLCJ0aW1lIjoiMjAxNi0wNi0xMVQwMToxMzoyMVoifQ" } ] bash$ curl -I http://localhost:5000/v2/busybox/manifests/latest HTTP/1.1 200 OK Content-Length: 2561 Content-Type: application/vnd.docker.distribution.manifest.v1+prettyjws Docker-Content-Digest: sha256:e45f25b1760f616e65f106b424f4ef29185fbd80822255d79dabc73b8eb715ad Docker-Distribution-Api-Version: registry/2.0 Etag: "sha256:e45f25b1760f616e65f106b424f4ef29185fbd80822255d79dabc73b8eb715ad" X-Content-Type-Options: nosniff Date: Sat, 11 Jun 2016 01:21:26 GMT 

No, where in any of these API calls can I find the desired 47bcc53 ... image id, which I see locally.

 bash$ docker inspect busybox:latest [ { "Id": "sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb", "RepoTags": [ "busybox:latest", "localhost:5000/busybox:latest" ], "RepoDigests": [], "Parent": "", "Comment": "", "Created": "2016-03-18T18:22:48.810791943Z", "Container": "5f8098ec29947b5bea80483cd3275008911ce87438fed628e34ec0c522665510", "ContainerConfig": { "Hostname": "156e10b83429", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": [ "/bin/sh", "-c", "#(nop) CMD [\"sh\"]" ], "Image": "56ed16bd6310cca65920c653a9bb22de6b235990dcaa1742ff839867aed730e5", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "DockerVersion": "1.9.1", "Author": "", "Config": { "Hostname": "156e10b83429", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": null, "Cmd": [ "sh" ], "Image": "56ed16bd6310cca65920c653a9bb22de6b235990dcaa1742ff839867aed730e5", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "Architecture": "amd64", "Os": "linux", "Size": 1112820, "VirtualSize": 1112820, "GraphDriver": { "Name": "aufs", "Data": null }, "RootFS": { "Type": "layers", "Layers": [ "sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6", "sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef" ] } } ] 

From this image spec> image identifier is a reproducible hash, and I see the same value for the image identifier on different systems.

ImageID Each image identifier is specified by the SHA256 hash of its JSON configuration. It is represented as a 256-bit hexadecimal encoding, for example sha256: a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9. Because the JSON configuration that receives hashed links hashes every layer in the image, this ImageID wording makes the image content-addresable.

So, if you can reproduce the JSON configuration from the API calls, you can create the image identifier yourself.

+1
source share

All Articles