解决dokcer容器时间与宿主机不一致问题方案
下面的方法不需要重启容器,也不需要重新创建容器
1. 查看时间差异
date
结果:
ll /etc/localtime
结果:
2. 重新建立软连接
rm /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ll /etc/localtime
date
结果:
成功解决!!!!!!!!
其实还有一种方法,但是可能有问题
**1.安装ntp、ntpdate **
#ubuntu
apt-get install ntp ntpdate -y
#centos
yum install ntpdate ntp -y
2. 同步时间
ntpdate cn.pool.ntp.org
ntpdate time.ntp.org
但是有的时候会因为启动容器的时候没有加系统参数而没有权限,如下报错:
所以还得用上面的那种方法,修改软连接,方便快捷
实在没有办法就得吧原来现有的容器进行commit,然后启动新容器如下连接
https://blog.csdn.net/weixin_40668374/article/details/107953909