Ubuntu timedatectl 在 Docker 容器中失败

Ubuntu timedatectl fails in Docker container

我在 Docker 容器(托管在 macOS 上)中安装了 Ubuntu 16.04 LTS 运行ning。 date/time 关闭了大约四天。

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
$ date
Sun May  7 05:57:21 UTC 2017

生效日期为 2017 年 5 月 11 日 06:17:13 UTC。

我想解决这个问题(检查 this and this)但我什至不能 运行 timedatectl:

$ timedatectl status
Failed to create bus connection: No such file or directory

我该如何解决这个问题?

时间漂移是由底层主机 OS 引起的,对于 Docker,它不是 macOS 但实际上是 Linux VM 运行在 Mac 上OS。它与 macOS 睡眠时间有关(例如,当您合上 MacBook 盖子时)。显然它最近已修复,应该很快可用:https://github.com/docker/for-mac/issues/17#issuecomment-300734810

回答实际提出的问题(如何在 Docker 容器中 运行 timedatectl status 时修复 Failed to create bus connection: No such file or directory

将以下标志添加到您的 docker run 命令中:

--privileged
--volume /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro

你需要 --privileged,否则你会得到 "Failed to query server: connection reset by peer"。音量标志似乎适用于 ro.