Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu timedatectl fails in Docker container

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?

like image 767
Marcel Stör Avatar asked May 11 '17 06:05

Marcel Stör


People also ask

Can you run Ubuntu in a Docker container?

There is a simplified method you can use to run Ubuntu Linux with a desktop environment. Many thanks to Docker! Using a Docker image, you can run Ubuntu with LXDE and LXQt desktop environments and access it via an HTML5 VNC interface.

Can't operate failed to connect to bus host is down Ubuntu?

The trick is to uninstall sudo apt-get remove docker docker.io containderd , etc... And add the docker GPG key and setup the repository (documented in link). Then install sudo apt-get install docker-ce docker-ce-cli containerd.io instead.

Can I run Ubuntu on Windows 10 using Docker?

Overview. It is now possible to run Docker containers on Windows 10 and Windows Server, leveraging Ubuntu as a hosting base. Imagine running your own Linux applications on Windows, using a Linux distribution you are comfortable with: Ubuntu!


2 Answers

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.

like image 123
srlm Avatar answered Sep 19 '22 03:09

srlm


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

like image 33
Marcel Stör Avatar answered Sep 20 '22 03:09

Marcel Stör