autesagar
(Autesagar)
December 22, 2021, 9:56am
1
Not able to fetch digetID from URL https://hub.docker.com/v2/repositories/{RepositoryName}/{DockerImageName}/tags/{Version}
Getting below message {“errinfo”:null,“message”:“object not found”}
Earlier I used to fetch digest id and image related information to validate docker image. But now we are not getting result from https+hub.docker.com+v2+repositories+{RepositoryName}/{DockerImageName}/tags/{Version} to validate docker image.
This URL is working for Open source Repository i.e. mongo
https://hub.docker.com/v2/repositories/library/mongo/tags/latest/
but not working for private repository.
rimelek
(Ákos Takács)
December 23, 2021, 3:47pm
2
The API endpoint doesn’t use the normal session so you have to authenticate yourself using a token. You can use this script:
#!/usr/bin/env bash
echo -n "Username: "
read -r username
echo -n "Password: "
read -rs password
echo
echo -n "Repository: "
read -r repository
auth_request="$(echo '{}' | jq --arg username $username --arg password $password '{"username": $username, "password": $password}')"
token=$(curl -s -H "Content-Type: application/json" -X POST -d "$auth_request" https://hub.docker.com/v2/users/login/ | jq -r .token)
curl -s -H "Authorization: JWT $token" "https://hub.docker.com/v2/repositories/$repository/tags/latest"
It will ask for username, password and the name of the repository.
Note: It requires “jq”
I have read this DockerHub Docker Registry API Examples
to create my version of the script.
You could also use hub-tool but it does not support setting the version tag:
hub-tool tag ls your/repository_without_tag --format json