Timedatectl: Failed to Create Bus Connection: No Such File or Directory

The scenario: I'm trying to set timezone on a docker container based on Ubuntu 18.04 docker image. Just pull the image, updated, and installed systemd

> apt-get -y update
> apt-get -y install systemd

The error: Failed to create bus connection: No such file or directory

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

The question: What I'm missing?

Note: There is no file localtime and timezone in directory etc

> ls /etc/localtime 
> ls: cannot access '/etc/localtime': No such file or directory
> ls /etc/timezone 
> ls: cannot access '/etc/timezone': No such file or directory

I've seen this and this but did not resolve, because dbus is not missing in my case

> apt-get install dbus
> dbus is already the newest version (1.12.2-1ubuntu1.1).

Thank you

3

2 Answers

This is caused by the container not having access to the system_bus_socket on the host. You need to run your container with:

docker run -ti -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro imagename /bin/bash

Then you'll be able to use the timedatectl command.

This worked for me

docker run --privileged -ti -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro imagename /bin/bash

Same solution Lauren suggested but has the --privileged flag added

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest