Centos7 modified container consistent time and host time

 First, the problem

centos7 container system time and time inconsistency host system, went in to see about it, found time and time zone on the host are inconsistent, following on to resolve what

Second, the phenomenon

1, the host See centos time enter a command to view

# date

[root @ localhost Docker-Server] # DATE 
2019 Nian 07 Wednesday, 31 May 11 : 42 : 23 CST

 

2, the following command to enter the vessel and then view the specified time following

# docker exec -it tjsp2 bash

[root@localhost docker-server]# docker exec -it tjsp2 bash
[root@cf8aa41a47f7 /]#
[root@cf8aa41a47f7 /]# date
Wed Jul 31 03:45:04 UTC 2019
[root@cf8aa41a47f7 /]#

 

Third, the summary

Found homed host using CST time, the container using the container UTC time, two different time zones. Lead time is not the same.

Fourth, the time synchronization docker container in the same host and

1, in the container modify / etc / localtime file name, to avoid conflict

# mv /etc/localtime /etc/localtime.bak

2, modify the zone to Shanghai

# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

3, and then see if the same time

[root@cf8aa41a47f7 /]# date
Wed Jul 31 12:00:44 CST 2019
[root@cf8aa41a47f7 /]#
[root@cf8aa41a47f7 /]# exit
exit
[root@localhost docker-server]#
[root@localhost docker-server]# date
2019年 07月 31日 星期三 12:00:47 CST
[root@localhost docker-server]#

 

Reference blog:

Docker container consistent time and modify host time

https://blog.csdn.net/qq_37054881/article/details/89964203

Guess you like

Origin www.cnblogs.com/djlsunshine/p/11275463.html