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 systemdThe error: Failed to create bus connection: No such file or directory
> timedatectl
> timedatectl: Failed to create bus connection: No such file or directoryThe 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 directoryI'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
32 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/bashThen 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/bashSame solution Lauren suggested but has the --privileged flag added