docker-archive / docker-registry

This is **DEPRECATED**! Please go to https://github.com/docker/distribution
Apache License 2.0
2.89k stars 877 forks source link

docker-registry shows wrong image created time #1052

Open Crayan opened 8 years ago

Crayan commented 8 years ago

I'm using registry v0.9.1. After I push an image to the private registry, I can see the image's json information. It includes this property:

"created":"2016-01-07T01:48:02.697017985Z"

However, this time is faster than my localtime. I ran the registry with -v /etc/localtime:/etc/localtime:ro option, which made the registry container's time in sync with the host. I ran the registry in this way:

docker run -t -i --name myregistry \ -v /etc/localtime:/etc/localtime:ro \ -p 5000:5000 \ -e standalone=True \ -e disable_token_auth=True \ registry:0.9.1 /bin/bash

It allows me to attach to the registry. I ran "date", the output showed the time was indeed in sync with the host. Then I ran "docker-registry" manually in an interactive way, and could see the output when I was pushing an image.

Naturally I assumed the "created" timestamp used the container's time, but it seems that's not the case. So my questions are:

  1. How is the "created" timestamp generated?
  2. How do I customize it so that the "created" timestamp uses my local time?

Thanks!

Crayan commented 8 years ago

Found the answer.

After searching through the code, I found in docker-registry/docker_registry/tags.py, there is such a line:

'last_update': int(time.mktime(datetime.datetime.utcnow().timetuple()))

As you can see, the time generated is the UTC time. I'm not sure this specific line is used to create the timestamp I saw, but I think even if it's not, they are all created in the same way, which is proved by the time gap I saw.