I am building a Docker image for running a bunch of background processes that communicate with each other using D-Bus. I am basing the image on Ubuntu Bionic. The system already works on native Debian 9.
What do I need to do to make D-Bus work inside the container? I have found some ideas by googling, but most questions on the internet are about using D-Bus between the container and the host, while I only need to connect processes running inside the container. My most successful attempts so far have failed with error message suggesting that there is something missing related to X11, which is true, because at this point, I don't have X11 installed at all.
An example of D-Bus service that I would run and connect to inside the container:
#!/usr/bin/env python import gobject import dbus import dbus.service import dbus.mainloop.glib import sys service_name = "com.testservice" object_path = "/testservice" interface_name = service_name class SomeObject(dbus.service.Object): def __init__(self, bus, object_path): dbus.service.Object.__init__(self, bus, object_path) @dbus.service.method(service_name, in_signature='', out_signature='') def Exit(self): mainloop.quit() if __name__ == '__main__': dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) session_bus = dbus.SessionBus() name = dbus.service.BusName(service_name, session_bus) object = SomeObject(session_bus, object_path) mainloop = gobject.MainLoop() mainloop.run()
Currently, attempting to start that service gives this output:
Traceback (most recent call last): File "/hostwork/dbus-test.py", line 35, in <module> session_bus = dbus.SessionBus() File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 211, in __new__ mainloop=mainloop) File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 100, in __new__ bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop) File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 122, in __new__ bus = cls._new_for_bus(address_or_type, mainloop=mainloop) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11