Docker timezone

Discussion room for Docker, a lightweight virtualization application that gives you the ability to run thousands of containers created by developers from all over the world on DSM
Forum rules
We've moved! Head over to Synology Community (community.synology.com) to meet up with our team and other Synology enthusiasts!
Korakal
I'm New!
I'm New!
Posts: 8
Joined: Tue Oct 10, 2017 8:11 pm

Docker timezone

Unread post by Korakal » Tue Oct 10, 2017 8:25 pm

Hi,

Because of the unavailability of many packages for my new DS918+, I decided to move my apps in use to Docker. Until now, I think it is a nice replacement. Although I had some trouble at startup (mainly related to rights assignment of shared folders), most things seems to run nice now.

There is one piece left that I don't understand and which I can't find much information about. I am in the Europe/Amsterdam timezone. I found out that providing the environment variable TZ and value 'Europe/Amsterdam', the right timezone should be reflected in my container. However, in what way I provide the variable, nothing seems to happen. I have tried 3 different containers (with different images, like MySQL and other applications). All logging runs 2 hours behind and when logging in into the container, I still see

Code: Select all

root@MySQL:/# cat /etc/timezone
Etc/UTC
I have tried 'Europe/Amsterdam', "Europe/Amsterdam", Europe/Amsterdam and the same variations with Etc/GMT+1 and even CET-1CEST,M3.5.0,M10.5.0/3 (which I found in another topic)

My Synology is set to the GMT+1-Amsterdam timezone and reflects the right time.

I don't understand it right now, anyone able to give some advice? Thanks!

Ben Diss
Rookie
Rookie
Posts: 31
Joined: Tue Jan 10, 2017 5:21 pm

Re: Docker timezone

Unread post by Ben Diss » Wed Oct 11, 2017 12:04 am

Check by just looking at the date.

Code: Select all

root@UniFi-Controller:/var/lib/unifi# cat /etc/timezone                                              
Etc/UTC                                                                                              
root@UniFi-Controller:/var/lib/unifi# date                                                           
Tue Oct 10 19:02:24 EDT 2017    

Korakal
I'm New!
I'm New!
Posts: 8
Joined: Tue Oct 10, 2017 8:11 pm

Re: Docker timezone

Unread post by Korakal » Wed Oct 11, 2017 6:49 am

That is interesting! The time seems to be reflected correctly when asking it with ‘date’, however the result I see in the Docker log (2nd tab from right in the Docker container properties) is always at UTC. I don’t hope that this is expected behaviour? :shock:

mightbetrue
Versed
Versed
Posts: 273
Joined: Sun Oct 02, 2016 9:41 am

Re: Docker timezone

Unread post by mightbetrue » Sat Oct 14, 2017 8:58 am

Not every image is prepared to make use of the TZ env variable.
You might want to try if it makes a change if you mount /etc/localtime into the container.

Hint: create a symlink pointing to /etc/localtime on one of your shares -> ln -s /etc/localtime /volume1/docker/localtime

Korakal
I'm New!
I'm New!
Posts: 8
Joined: Tue Oct 10, 2017 8:11 pm

Re: Docker timezone

Unread post by Korakal » Mon Oct 16, 2017 7:00 pm

Thanks for the suggestion. I have created the symlink but still I see the log timestamps (at the Synology Docker container pages, tab 'log') being created at UTC. However, if I log in into the container, the time is showing up correctly... very weird :o

mightbetrue
Versed
Versed
Posts: 273
Joined: Sun Oct 02, 2016 9:41 am

Re: Docker timezone

Unread post by mightbetrue » Mon Oct 16, 2017 7:09 pm

Did you mount /volume1/docker/localtime as a docker volume into the container at /etc/localtime?

Korakal
I'm New!
I'm New!
Posts: 8
Joined: Tue Oct 10, 2017 8:11 pm

Re: Docker timezone

Unread post by Korakal » Tue Oct 17, 2017 9:33 pm

mightbetrue wrote: ln -s /etc/localtime /volume1/docker/localtime
This is what I executed at the Synology host, as suggested im your previous message. Afterwards I rebooted the containers. Not good?
Thanks for your help so far, by the way. Appreciated!

mightbetrue
Versed
Versed
Posts: 273
Joined: Sun Oct 02, 2016 9:41 am

Re: Docker timezone

Unread post by mightbetrue » Tue Oct 17, 2017 9:56 pm

The symlink doesn't do anything by itself. It is intended to place a symlink to localtime to a folder that can be accessed from docker (it is a synology only restriction).
In order to make use of it in the container, you need to map a volume from the created symlink to /etc/localtime inside the container.

lateparty
I'm New!
I'm New!
Posts: 1
Joined: Sat Jun 02, 2018 10:47 am

Re: Docker timezone

Unread post by lateparty » Sat Jun 02, 2018 10:50 am

Worth noting for anyone that stumbles upon this.

(Edit 1) DSM will display files owned by root, but you won't see this symlink in DSM and therefore not in the Docker GUI either.

To get around this without going into the CLI, simply find any other file you can see set it as the /etc/localtime path, and then edit its path accordingly i.e. /<path>/<to>/localtime e.g. /docker/localtime

mightbetrue
Versed
Versed
Posts: 273
Joined: Sun Oct 02, 2016 9:41 am

Re: Docker timezone

Unread post by mightbetrue » Sun Jun 03, 2018 11:33 am

lateparty wrote:
Sat Jun 02, 2018 10:50 am
(Edit 1) DSM will display files owned by root, ...
The owner doesn't matter. The ui allows to select files owned by a restricted user as well, as long as the file permissions allow it.
lateparty wrote:
Sat Jun 02, 2018 10:50 am
..., but you won't see this symlink in DSM and therefore not in the Docker GUI either.
I never realized it, because I allways start my containers from the CLI...
Good catch! Neither my symlink to /var/run/docker.sock, nor /etc/localtime are listed in the file picker.
lateparty wrote:
Sat Jun 02, 2018 10:50 am
To get around this without going into the CLI, simply find any other file you can see set it as the /etc/localtime path, and then edit its path accordingly i.e. /<path>/<to>/localtime e.g. /docker/localtime
At least for me, the left hand side of the path (path to the symlink) can neither be changed on container creation, nor while editing an existing stopped container.

Did you perhaps forget to mention that the container configuration needs to be exported, manually edited and re-importet again? If your approach is different, please elaborate how you did it.

BobW
Beginner
Beginner
Posts: 28
Joined: Wed Sep 18, 2013 3:32 pm

Re: Docker timezone

Unread post by BobW » Sun Sep 23, 2018 6:09 pm

So I was wondering if this problem was ever solved for you? Because i'm facing the same issues/problems with my docker logs. The log time isn't showing correct but the NAS has the correct time.

Locked

Return to “Docker”