Ubuntu timedatectl fails in Docker container

Marcel Stör picture Marcel Stör · May 11, 2017 · Viewed 18.5k times · Source

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?

Answer

srlm picture srlm · Oct 19, 2017

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.