Docker container time is inconsistent with host time
Viewing time through the date command
View host Time
[root@localhost ~]# Date
July 27, 2016 Wednesday 22:42:44 CST
View Container Time
root@b43340ecf5ef:/#date
Wed June 14:43:31 UTC 2016
They were found to be 8 hours apart.
CST should refer to (Shanghai time, East eight)
UTC should mean (Coordinated Universal time, standard times)
So, these 2 times should actually be 8 hours apart. (bluer: So there is no set of containers, generally with host time difference between 8h)
Therefore, you must unify the time zone for both.
LocalTime of Shared hosts ( method I )
Specify the startup parameters when creating the container, mount the localtime file into the container, and ensure that the time zone used is the same.
Replication Host LocalTime ( method two )
Docker cp/etc/localtime: "Container ID or name"/etc/localtime
When finished, the current time is viewed through the date command.
However, the time of the program running in the container may not be updated, such as the MySQL service running in the container, and after the update time, view the MySQL time through SQL
It can be found that time has not changed over.
At this point, you must restart the MySQL service or restart the Docker container, MySQL can read the time after the change.
Create a custom Dockerfile ( Method III )
Creating a Dockerfile file, in fact, has nothing to do with customizing the time format of the mirror in the timely area.
From Redis to
Tomcat
ENV catalina_home/usr/local/tomcat
#设置时区
run/bin/cp/usr/share/zoneinfo/ Asia/shanghai/etc/localtime \
&& echo ' Asia/shanghai ' >/etc/timezone \
Once saved, use the Docker build command to generate mirror usage.
Thank you for reading, I hope to help you, thank you for your support for this site!