Docker 容器间时间同步
一、实现原理:首先宿主机间实现时间同步,然后容器启动时以只读方式挂载宿主机的/etc/localtime文件实现各宿主机上的Docker容器间的时间同步。二、操作步骤
1、宿主机修改时区
# cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cp: overwrite ‘/etc/localtime’? y
# date
Sun Jan3 11:49:33 CST 2016 2、安装ntpd服务,并设置开机自启动
# yum install ntp -y
# systemctl enable ntpd
ln -s '/usr/lib/systemd/system/ntpd.service' '/etc/systemd/system/multi-user.target.wants/ntpd.service' 3、宿主机与ntp.api.bz同步
# ntpdate ntp.api.bz
3 Jan 11:52:33 ntpdate: adjust time server 61.153.197.226 offset 0.034242 sec 4、启动ntpd service
# systemctl start ntpd.service 5、启动容器
# docker run -ti -d--name test registry.tingyun.com/tingyun/common/centos:7 -v /etc/localtime:/etc/localtime:ro /bin/bash
fd8e9ab132d3802b2c8eee3caf79dc547a1e3f025adc3ee5316eda7d967a1b11
# date
Sun Jan3 12:07:21 CST 2016
# dockerexec -ti test /bin/bash
# date
Sun Jan3 12:07:34 CST 2016
页:
[1]