I have a problem when the current timezone is not determined correctly in a JVM instance running inside a Docker container (both host and container are Cent OS 6.5).
First of all I have mapped etc/localtime
to the child container via -v /etc/localtime:/etc/localtime:ro
(I think it's a prevalent way)
When I login via SSH both on host and container
date -u
prints
Mon Apr 20 11:48:57 UTC 2015
and
date
prints
Mon Apr 20 14:50:41 MSK 2015
In JVM however with
System.out.println(new Date());
I get Mon Apr 20 11:52:24 UTC 2015
inside container and Mon Apr 20 14:53:17 MSK 2015
inside the host.
How is the current timezone determined exactly?
Oracle FAQ did not shed the light, I don't quite understand what metrics Java does Java use to get timezone for the current user
Do my operating system's timezone patches fix the Java platform's timezone data?
No. The Java SE platform's timezone data is not read from the local or host operating system. The Java SE platform maintains a private repository of timezone data in locally installed files ( .../jre/lib/zi) as part of the Java Runtime Environment (JRE) software. Applying whatever operating system timezone patches (for example Solaris OS, Linux, Windows) will have no effect on the accuracy of the Java SE platform's timezone data.
update: if someone is interested in workaround - I've specified TZ environment variable as in Stephen's answer, so now the container is created with parameters
-v /etc/localtime:/etc/localtime:ro -e "TZ=Europe/Moscow"