Ubuntu timedatectl fails in Docker container
Asked Answered
P

2

20

I've got Ubuntu 16.04 LTS running in a Docker container (hosted on macOS). The date/time is off by about four days.

$ 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

Effective date is 11 May 2017 06:17:13 UTC.

I wanted to fix this (checking this and this) but I can't even run timedatectl:

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

How do I fix this?

Paeon answered 11/5, 2017 at 6:22 Comment(5)
Please see if this post helps - serverfault.com/questions/683605/… or #40235347Monad
Nope, the issue isn't that the timezone is incorrect, I'm fine with UTC. ls -l /etc/localtime shows that it correctly points to /usr/share/zoneinfo/Etc/UTC. Running dpkg-reconfigure -f noninteractive tzdata thus doesn't have any effect, the date is still off by ~4d.Efrem
Picked up the same ubuntu image on different os's(windows / linux), showing UTC and is correct. Hope there is no issue with time in the host machine. Any idea to reproduce it?Monad
date on the host OS returns the correct values. To reproduce you can run docker run --rm -ti marcelstoer/nodemcu-build date.Efrem
Thank you, shows correct Thu May 11 08:06:23 UTC 2017Monad
P
4

Time drift is caused by the underlying host OS which, for Docker, isn't macOS but actually the Linux VM running on macOS. It's related to macOS sleep times (e.g. when you close the MacBook lid). Apparently it has recently been fixed and should be available soon: https://github.com/docker/for-mac/issues/17#issuecomment-300734810

Paeon answered 12/6, 2017 at 13:14 Comment(0)
I
9

To answer the actual question that was asked (how to fix Failed to create bus connection: No such file or directory when running timedatectl status in a Docker container):

Add the following flags to your docker run command:

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

You need the --privileged, otherwise you get a "Failed to query server: connection reset by peer". The volume flag seems to work fine with ro.

Ides answered 19/10, 2017 at 19:1 Comment(4)
If I mount /run/dbus I get the following error. "Error starting container cf2e79d525716ac9c926980d16a0753b1b296fd5965d3c58003620d2608656a3: 502 Server Error: Bad Gateway (\"Mounts denied: \r\nThe path /run/dbus/system_bus_socket\r\nis not shared from OS X and is not known to Docker.\r\nYou can configure shared paths from Docker -> Preferences... -> File Sharing.\r\nSee docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.Agace
dbus missing from the base image, apt-get install dbus resolved problemAgace
Is there any way to do this without the privileged flag? bitbucket pipelines don't allow docker containers to be run in privileged modeOrient
Does not work for me on Windows 10.Coom
P
4

Time drift is caused by the underlying host OS which, for Docker, isn't macOS but actually the Linux VM running on macOS. It's related to macOS sleep times (e.g. when you close the MacBook lid). Apparently it has recently been fixed and should be available soon: https://github.com/docker/for-mac/issues/17#issuecomment-300734810

Paeon answered 12/6, 2017 at 13:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.