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

Source: Internet
Author: User
Tags docker cp docker run

Original: http://www.jb51.net/article/99906.htm

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.

1 Docker run--name <name>-v/etc/localtime:/etc/localtime:ro ....

localtime of replication host (Method II) ?

1 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 does not necessarily update, such as the MySQL service running in the container, after the update time, the time to view MySQL through SQL?

1 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)

Create Dockerfile file, in fact, there is no content, that is, customize the mirror time format in time.

1 2 3 4 5 6 7 8 9 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.

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.