是否有可能从Docker Registry V2获取图像ID?

当图像被推送到registryV2时,图像ID是否也会被推送到registry中? 是否有可能从V2registry获取某个存储库的图像ID?

如果使用Docker Client 1.10或更高版本推送图像,则可以从registry中获取图像ID

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

您的请求必须包含标题

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

在响应中,图像ID将位于Content-Docker-Digest响应头中。

从我的研究,你可以从registry(2.3.0 +)获取图像ID

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

而响应中的config.digest字段代表imageID,那就是你想要的!

例如

指: https : //duyanghao.github.io/docker-registry-pull-manifest-v2/

尽我所知,他们不存储在任何API访问位置:

 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 

没有在这些API调用的任何地方,我可以find所需的47bcc53 …我在本地看到的图像ID。

 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" ] } } ] 

从这个图像规格的图像ID是一个可重复的哈希,我看到不同的系统上的图像ID相同的值。

ImageID每个图像的ID由其configurationJSON的SHA256哈希给出。 它被表示为256位的hex编码,例如,sha256:a9561eb1b190625c9adb5a9513e72c4dedafc1cb2d4c5236c9a6957ec7dfd5a9。 由于获取哈希的configurationJSON引用图像中每个图层的散列,因此ImageID的这种表示使得图像可以被内容添加。

因此,如果您可以从API调用中重新生成configurationJSON,那么您可以自己生成图像标识。