Skip to content

How to connect container to DBus from host

mviereck edited this page Jun 8, 2019 · 11 revisions

How to connect container to DBus from host

Normally there are two DBus daemons running on the host system. One is the system daemon, the other one is the user session daemon. For most use cases you will need the user session daemon, but not the system daemon.

  • x11docker provides access to host DBus user session daemon with option --hostdbus. For security reasons, rather use options --dbus or --dbus-system to run DBus inside of container without being conneced to the host.
  • To just run a DBus user daemon in container without x11docker and without being connected to the host, use dbus-launch or dbus-run-session to run the image command.

DBus user session daemon

The DBus user session daemon can have a real or an abstract unix socket. Check the output of echo $DBUS_SESSION_BUS_ADDRESS.

  • If it contains unix:path, it is a real unix socket within file system.
  • If it contains unix:abstract, it is an abstract unix socket.

DBus with real unix socket in file system

  • Example: DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
  • Set this variable as it is given: --env DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS"
  • Share the given socket file: --volume /run/user/1000/bus:/run/user/1000/bus
  • Run image with same user as on host: --user $(id -u):$(id -g)
  • Test: Run notify-send "hello host" in container.

DBus with abstract unix socket

  • Example: DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-KDKGRIL7QX,guid=221d2f667e843d50fd1dc6a05babf8ae
  • Set this variable as it is given: --env DBUS_SESSION_BUS_ADDRESS="$DBUS_SESSION_BUS_ADDRESS"
  • Allow access with --network=host. This is an unfortunate insecure solution that shares host network stack with container.

DBus system daemon

Share DBus system daemon with --volume /run/dbus/system_bus_socket:/run/dbus/system_bus_socket.

Clone this wiki locally