In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "Docker how to solve the inconsistency between container time and host time". In daily operation, I believe many people have doubts about how Docker solves the inconsistency between container time and host time. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the question of "Docker how to solve the inconsistency between container time and host time"! Next, please follow the small series to learn together!
Docker container time inconsistent with host time
Check the time with the date command
View host time
[root@localhost ~]# date Wednesday July 27th, 2016 22:42:44 CST
View container time
root@b43340ecf5ef:/#date Wed Jul 27 14:43:31 UTC 2016
It can be seen that they are 8 hours apart.
CST should mean (China Shanghai Time)
UTC means Coordinated Universal Time.
So, these two times should actually be eight hours apart. (bluer: so there is no container that has been set up, usually 8h different from the host time)
Therefore, the time zones of the two must be unified.
The localtime of the shared host (Method 1)
Specify startup parameters when creating the container, mount the localtime file into the container, and ensure that the time zone used by the two is the same.
docker run -d -v /etc/localtime:/etc/localtime --rm -p 8888:8080 tomcat:latest localtime of replication host (method 2)docker cp /etc/localtime [container ID or NAME]:/etc/localtime
After completion, check the current time with the date command.
However, the time of the program running in the container may not be updated, such as MySQL service running in the container. After updating the time, check the time of MySQL through sql.
select now() from dual;
It can be seen that the time has not changed.
At this time, you must restart mysql service or restart Docker container, mysql can read the time after the change.
Create a custom dockerfile (Method 3)
Create a dockerfile file, in fact, there is nothing, is to customize the time format and time zone of the mirror.
FROM redisFROM tomcatENV CATALINA_HOME /usr/local/tomcat#setting timezone RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo 'Asia/Shanghai'>/etc/timezone \
After saving, you can use docker build command to generate an image.
At this point, the study of "Docker how to solve the inconsistency between container time and host time" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.