如何确保 docker 的时间与主机的时间同步? [英] How to make sure docker's time syncs with that of the host?

查看:38
本文介绍了如何确保 docker 的时间与主机的时间同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Linode 服务器上运行了 docker.有时,我发现码头工人的时间不对.目前我已经更改了每个 docker 中的运行脚本以包含以下代码行.

I have dockers running on Linode servers. At times, I see that the time is not right on the dockers. Currently I have changed the run script in every docker to include the following lines of code.

yum install -y ntp
service ntpd stop
ntpdate pool.ntp.org

然而,我最想做的是 docker 应该与主机同步时间.有没有办法做到这一点?

What I would ideally like to do however is that the docker should sync time with the host. Is there a way to do this?

推荐答案

这个答案的来源是对答案的评论:docker 容器会自动与主机同步时间吗?

The source for this answer is the comment to the answer at: Will docker container auto sync time with the host machine?

看了答案后,我意识到docker容器上不会发生时钟漂移.Docker 使用与主机相同的时钟,Docker 无法更改它.这意味着在 docker 中执行 ntpdate 不起作用.

After looking at the answer, I realized that there is no way a clock drift will occur on the docker container. Docker uses the same clock as the host and the docker cannot change it. It means that doing an ntpdate inside the docker does not work.

正确的做法是使用ntpdate

就同步时区而言,-v/etc/localtime:/etc/localtime:ro 有效.

As far as syncing timezones is concerned, -v /etc/localtime:/etc/localtime:ro works.

这篇关于如何确保 docker 的时间与主机的时间同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆