10

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

2 Answers2

2

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.

Lauren
  • 21
2

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