Access DBus from container


I’m trying to get access to system DBus from within a C++ container. I made it privileged like this and added bind mounts corresponding to other threads I found on this forum:


The code to open a DBus connection goes like this:

    DBusError err;
    int ret;
    // initialise the errors

    std::cout << "Establishing DBus connection..." << std::endl;
    DBusConnection* conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
    if (dbus_error_is_set(&err)) { 
        fprintf(stderr, "Connection Error (%s)\n", err.message); 

    if(conn == NULL) {
        std::cout << "Could not establish DBus connection" << std::endl;
    else {
        std::cout << "Connection set up" << std::endl;

I always get the following error:

Connection Error (Unable to autolaunch a dbus-daemon without a $DISPLAY for X11)

What else should I do to get access to system DBus?

Kind regards,

I’m an idiot. Using DBUS_BUS_SYSTEM instead of DBUS_BUS_SESSION did the trick.