Docker solve the problem of inconsistent container time and host time three kinds of solutions _docker

Source: Internet
Author: User
Tags current time tomcat docker cp

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

Select Now () from dual;

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.