Given a tag `latest`, we want to find out another tag with the same image ID on Docker Hub.
Here is how to find out all tags for a repo with the Docker Hub API v2:
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/fluent/fluentd/tags/?page_size=100 | jq
(See gist.github.com/kizbitz)
Unfortunately, it doesn't contain the image ID but always a `null` value for this key:
$ curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/fluent/fluentd/tags/?page_size=100 | jq
{
"count": 36,
"next": null,
"previous": null,
"results": [
...
{
"name": "v0.14.11",
"full_size": 11964464,
"id": 7084687,
"repository": 219785,
"creator": 2923,
"last_updater": 2923,
"last_updated": "2016-12-27T07:16:41.294807Z",
"image_id": null,
"v2": true,
"platforms": [
5
]
},
...
Unfortunately, the image ID is something different than the `id` in the JSON above.
$ docker images | grep fluent
docker.io/fluent/fluentd v0.14.11 1441d57beff9 3 weeks ago 38.25 MB
Theoretically, it should be possible to access the Docker Manifests and along with the the image ID with this Docker Registry call but it doesn't help either:
$ curl -s -H "Authorization: JWT ${TOKEN}" "https://registry.hub.docker.com/v2/fluent/fluentd/manifests/latest"
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Name":"fluent/fluentd","Action":"pull"}]}]}
(See stackoverflow.com)
Here is a similar issue in the Docker GitHub repo but I still cannot figure out the solution: https://github.com/docker/distribution/issues/1490 .
P.S.: Here is my Docker version with which I tried to push a test image:
$ docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-common-1.12.6-5.git037a2f5.fc25.x86_64
Go version: go1.7.4
Git commit: 037a2f5/1.12.6
Built: Wed Jan 18 12:11:29 2017
OS/Arch: linux/amd64
Docker Registry API v2 uses image digest instead of image ID to distinguish image identity.
The image digest can be obtained from
Docker-Content-Digest
of the HTTP response header by making the following API call:All tags can be obtained with the following API call:
Based on the above, to find the same digest as a specific tag, it will be a script like the following.
The result is as follows:
If you want to check the digest of the local image, you can get it with
docker images --digests
:The above answer is great! In addition, if you want to use this on a private repo, you need to add basic auth with your registry user credentials, and the additional scope parameter 'account='
(see http://www.cakesolutions.net/teamblogs/docker-registry-api-calls-as-an-authenticated-user)