Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the creation date of an image in a (private) Docker registry (API v2)?

I would like to find out the latest timestamp for an image in a private Docker registry using the v2 API without first pulling the image to my local host.

like image 587
snth Avatar asked Sep 16 '15 10:09

snth


People also ask

What is docker registry V2?

The Docker Registry HTTP API is the protocol to facilitate distribution of images to the docker engine. It interacts with instances of the docker registry, which is a service to manage information about docker images and enable their distribution.

How can I list all tags for a docker image on a remote registry?

You can just create a new file name, dockertags , under /usr/local/bin (or add a PATH env to your . bashrc / . zshrc ), and put that code in it. Then add the executable permissions( chmod +x dockertags ).

What is private registry in docker?

A private Docker registry allows you to share your custom base images within your organization, keeping a consistent, private, and centralized source of truth for the building blocks of your architecture.


2 Answers

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!

like image 127
snth Avatar answered Sep 20 '22 22:09

snth


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
like image 34
Sebastian Wagner Avatar answered Sep 18 '22 22:09

Sebastian Wagner