19

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?

5
  • Please see if this post helps - serverfault.com/questions/683605/… or stackoverflow.com/questions/40234847/…
    – Rao
    May 11, 2017 at 6:26
  • 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. May 11, 2017 at 7:07
  • 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?
    – Rao
    May 11, 2017 at 7:45
  • date on the host OS returns the correct values. To reproduce you can run docker run --rm -ti marcelstoer/nodemcu-build date. May 11, 2017 at 8:01
  • Thank you, shows correct Thu May 11 08:06:23 UTC 2017
    – Rao
    May 11, 2017 at 8:06

2 Answers 2

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.

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. Feb 26, 2018 at 11:28
  • 2
    dbus missing from the base image, apt-get install dbus resolved problem Feb 26, 2018 at 13:35
  • 2
    Is there any way to do this without the privileged flag? bitbucket pipelines don't allow docker containers to be run in privileged mode Aug 10, 2018 at 14:56
  • Does not work for me on Windows 10. Feb 10, 2022 at 8:00
2

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.