Setup docker container to communicate with host over d-bus

I've found a solution. Here's my Dockerfile:

FROM i386/ubuntu:16.04

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y dbus

COPY dbus.conf /etc/dbus-1/session.d/

ENTRYPOINT ["dbus-run-session", "slaveApp"]

And my dbus.conf:

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
    "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">

<busconfig>
    <listen>tcp:host=localhost,bind=*,port=6667,family=ipv4</listen>
    <listen>unix:tmpdir=/tmp</listen>
    <auth>ANONYMOUS</auth>
    <allow_anonymous/>
</busconfig>

And set the address variable on host:

export DBUS_SESSION_BUS_ADDRESS=tcp:host=${containerIp},port=6667,family=ipv4

In my master app I initiate a connection (I used Qt):

 QDBusConnection::connectToBus("tcp:host=${containerIp},port=6667", "qt_default_session_bus"); 

The master app can now send messages to slave app. I haven't tried to send messages from slave to master, though.

The answer is taken from this post: https://stackoverflow.com/a/45487266/6509266

Tags:

Docker

D Bus