How to find the creation date of an image in a (private) Docker registry (API v2)?
A minor improvement to the answer from @snth : print the date more user friendly by using date
:
date --date=$(curl -s -X GET http://$REGISTRY:5000/v2/$IMAGE/manifests/$TAG | \
jq -r '.history[].v1Compatibility' | jq -r '.created' | sort | tail -n 1 )
Prints something like:
Fr 12. Okt 15:26:03 CEST 2018
Compiling the comments and answers above here is a complete solution
With Authentication
# Setup variables to make this more usalbe
USERNAME=docker_user
PASSWORD=docker_pass
DOCKER_REGISTRY=http://my-registry.myorg.org:9080
REPO=myrepo
TAG=atag
# Query Registry and pipe results to jq
DOCKER_DATE=$(curl -s -u $USERNAME:$PASSWORD -H 'Accept: application/vnd.docker.distribution.manifest.v1+json' -X GET http://$REGISTRY_URL/v2/circle-lb/manifests/master | jq -r '[.history[]]|map(.v1Compatibility|fromjson|.created)|sort|reverse|.[0]')
echo "Date for $REPO:$TAG is $DOCKER_DATE"
Without Authentication
DOCKER_DATE=$(curl -s -H 'Accept: application/vnd.docker.distribution.manifest.v1+json' -X GET http://$REGISTRY_URL/v2/circle-lb/manifests/master | jq -r '[.history[]]|map(.v1Compatibility|fromjson|.created)|sort|reverse|.[0]')
And lastly if you want to parse with the date command (gnu date)
on linux:
date -d $DOCKER_DATE
on mac:
gdate -d $DOCKER_DATE
So after some hacking around, I got the following to work using the curl
and jq
tools:
curl -X GET http://registry:5000/v2/<IMAGE>/manifests/<TAG> \
| jq -r '.history[].v1Compatibility' \
| jq '.created' \
| sort \
| tail -n1
This seems to work but I don't really know how the v1 Compatibility representation is to be interpreted so I don't know if I am really getting the correct number out of this.
Comments on this are welcome!