4

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
  • watch this question, also this one too – damadam Nov 22 '19 at 9:55
  • thank you but did not resolve because dbus is not missing in my case: dbus is already the newest version (1.12.2-1ubuntu1.1). (improved the question) – GabrieleMartini Nov 22 '19 at 10:02
  • expecting the same difficulties with ubuntu 16.04 – Ladenkov Vladislav Jul 14 '20 at 17:21
1

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.

1

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

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