Docker容器的日期/时间与主机PC完全不同 [英] Docker container date/time totally different to host PC

查看:74
本文介绍了Docker容器的日期/时间与主机PC完全不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在PC上运行Docker容器时,它与主机PC的日期/时间完全不同.请参阅下面的命令.容器识别器Dev上的时间是主机的前一天,不同的时间,不同的分钟.知道发生了什么吗?

When I run a docker container on my PC it has a totally different date/time to the host PC. See commands below. The time on the container recognizerDev is for the previous day, different hour, different minutes to the host. Any idea what is going on?

PS C:\Users\Bobby> date
11 October 2016 19:51:38

PS C:\Users\Bobby> docker exec recognizerDev date
Mon Oct 10 21:43:54 UTC 2016

当我尝试在AWS linux主机上运行的同一事物时,日期/时间是正确的,但由于时区不同,相差1小时.

When I try the same thing running on an AWS linux host the date/time is correct except for a 1 hour difference due to timezones.

请注意,根据我的PC,第一个命令以UTC + 1(伦敦)返回正确的时间/日期.第二个命令说它是在UTC中,但这不可能正确,就好像它会在不到1小时的时间内返回相同的结果.

Note that the first command returns the correct time/date in UTC+1 (London) as per my PC. The second command says it is in UTC but this cannot be right as if so it would return the same result less 1 hour.

推荐答案

这只是部分答案(因为它不一定能解决问题),但可能有助于诊断.

This is only a partial answer (because it does not necessarily resolve the problem), but may help with diagnosis.

当您在Linux下运行docker(如在AWS主机上)时,您仅在主机上运行进程.也就是说, docker run fedora ls 与运行 ls 之间没有实质性区别,除了前者对系统资源的看法略有不同.容器中报告的时间将始终与主机上报告的时间匹配,以时区为模.

When you are running docker under Linux (as on your AWS host), you are just running processes on the host. That is, there isn't a substantial difference between docker run fedora ls vs running ls, except that the former has a slightly different view of system resources. The time reported in the container will always match the time reported on the host, modulo timezone settings.

当您在其他任何地方(例如,在Windows或MacOS下)运行docker时,会出现一个附加的层:docker生成Linux虚拟机(历史上使用VirtualBox,尽管我认为它们可能

When you running docker anywhere else (e.g., under Windows or MacOS), there is an additional layer in play: docker spawns a Linux virtual machine (historically using VirtualBox, although I think they may take advantage of other options these days) and then runs docker inside the virtual machine.

因为这实际上是与您的主机不同的机器,所以时间可能会漂移.有多种解决此类问题的方法,包括在虚拟机内部运行ntp或运行特殊的来宾代理,以确保时间与主机保持同步.我对Docker如何配置这些系统以了解它们是否或如何明确处理这一点还不了解.

Because this is effectively a different machine from your host, it is possible for the time to drift. There are various ways of solving this sort of problem, including running ntp inside the virtual machine or running special guest agents that take care of keeping time in sync with the host. I don't know enough about how Docker configures these systems to know how or if they handle this explicitly.

如果您的docker vm已经运行了很长时间,只需重新启动它即可解决问题.您可能需要 docker计算机重启.

If your docker vm has been running for a long period of time, simply restarting it may resolve the problem. Possibly docker machine restart is what you need.

这篇关于Docker容器的日期/时间与主机PC完全不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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