# Dbus: Failed to connect to socket /host/run/dbus/system

**URL:** <https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107>\
**Category:** Product support\
**Created:** [May 9, 2018, 9:33am UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107 "2018-05-09T09:33:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zagatta-sonah](https://avatars.discourse-cdn.com/v4/letter/z/e47c2d/32.png) [@zagatta-sonah](https://forums.balena.io/u/zagatta-sonah)\
**Post date:** [May 9, 2018, 9:33am UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/1 "2018-05-09T09:33:04Z")

</div>

I am trying to check if the time was NTP synchronized.  
I connect via resin CLI and then go into one of my containers.

```auto
root@a6e385b:~# balena exec -it 4aba7fde2842 bin//bash
root@raspberrypi3-a6e385b:/# DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
> dbus-send \
> --system \
> --print-reply \
> --reply-timeout=2000 \
> --type=method_call \
> --dest=org.freedesktop.timedate1 \
> /org/freedesktop/timedate1 \
> org.freedesktop.DBus.Properties.GetAll \
> string:"org.freedesktop.timedate1"
Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

```

Any idea what went wrong?

---

<div class="post-metadata">

**Author:** ![chrischabot](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrischabot/32/871_2.png) [@chrischabot](https://forums.balena.io/u/chrischabot)\
**Post date:** [May 9, 2018, 12:22pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/4 "2018-05-09T12:22:49Z")

</div>

Hi @zagatta-sonah!

If you’re using a multi-container setup, you have to specifically specify which container(s) will get access to the DBUS socket via labels in the docker-compose.yml file, see: [https://docs.resin.io/learn/develop/multicontainer/#labels](https://docs.resin.io/learn/develop/multicontainer/#labels)

Let us know if that helps!

---

<div class="post-metadata">

**Author:** ![r4space](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@r4space](https://forums.balena.io/u/r4space)\
**Post date:** [December 4, 2018, 12:49pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/6 "2018-12-04T12:49:33Z")

</div>

And if I’m running a single container?

Had the same response from Python so tried in bash but also getting:

```
RUN apt-get update \
&& apt-get install -yq ccache wireless-tools dbus 
RUN export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
RUN DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
dbus-send \
  --system \
  --print-reply \
  --reply-timeout=2000 \
  --type=method_call \
  --dest=org.freedesktop.NetworkManager \
  /org/freedesktop/NetworkManager \
  org.freedesktop.DBus.Properties.GetAll \
  string:"org.freedesktop.NetworkManager" 

Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory
```

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [December 4, 2018, 1:03pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/9 "2018-12-04T13:03:15Z")

</div>

You are using the dbus-send command inside the Dockerfile. Instead of invoking it during build time, you need to do that in runtime from your start.sh script.

---

<div class="post-metadata">

**Author:** ![r4space](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@r4space](https://forums.balena.io/u/r4space)\
**Post date:** [December 4, 2018, 2:34pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/10 "2018-12-04T14:34:22Z")

</div>

Elaborate?

I’m really just trying to get the python dbus api working but can’t get beyond invoking  
import dbus  
bus = dbus.SystemBus()

Get the same error about no such file

Was just trying bash as a pre-test

Advice?

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [December 4, 2018, 10:37pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/11 "2018-12-04T22:37:53Z")

</div>

@r4space, I believe I understand @majorz 's answer, although I don’t have much experience with dbus. It’s about the difference between the Dockerfile “instructions” RUN, CMD or ENTRYPOINT. The RUN instruction executes something that should modify the filesystem as a step to produce a docker image. Each RUN command results in a “layer” for the final image, and this is what majorz referred to as “build time”. The CMD and ENTRYPOINT instructions, on the other hand, specify something to be executed when your app container is started, which majorz called “runtime”.  
Quoting balena’s Dockerfile documentation page:

- [https://www.balena.io/docs/learn/develop/dockerfile/](https://www.balena.io/docs/learn/develop/dockerfile/)
- **CMD** - _This command will be run when the container starts up on your device, whereas RUN commands will be executed on our build servers. In a balena application, this is typically used to execute a start script or entrypoint for the users application. CMD should always be the last command in your Dockerfile. The only processes that will run inside the container are the CMD command and all processes that it spawns._
- **[Init System](https://www.balena.io/docs/learn/develop/dockerfile/#init-system)** - _Whatever you define as CMD in your Dockerfile will be PID 1 of the process tree in your container. It also means that this PID 1 process needs to know how to properly process UNIX signals, reap orphan zombie processes and if it crashes, your whole container crashes, meaning you lose logs and debug info._

So instead of these two lines:

```auto
RUN export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
RUN ... dbus-send ...

```

Try placing the commands inside a shell script (could also be a Python script) (which majorz called “start.sh”) and running that script with the CMD instruction, something like:

```auto
COPY ./my_dbus_test.sh my_dbus_test.sh
CMD my_dbus_test.sh

```

Note that whatever you execute with CMD (like `my_dbus_test.sh`) should be a “long-lived” process if you are planning to upload it through balena’s platform (git push or balena push). If it’s a script that runs and quits straight away, then if I recall correctly the supervisor will keep restarting the container in an endless loop and you won’t be able to see / interact with it. (You can tell I’ve learned the hard way…) 🙂

---

<div class="post-metadata">

**Author:** ![mowi22](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mowi22/32/2416_2.png) [@mowi22](https://forums.balena.io/u/mowi22)\
**Post date:** [August 23, 2019, 3:52pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/13 "2019-08-23T15:52:02Z")

</div>

Hey guys, I have the labels in the docker compose but Im still coming up with this error on electron.

electron: 1.7.13  
node: 10

Im running the balena-electron-react package in a multi-container configuration. I have this in my compose file

```auto
    build: ./electron
    privileged: true
    restart: always
    network_mode: host
    depends_on:
    - wifi-connect
    - gateway
    ports:
      - "5858:5858"
      - "8080:8080"
    labels:
      io.balena.features.kernel-modules: '1'
      io.balena.features.firmware: '1'
      io.balena.features.dbus: '1'
      io.balena.features.supervisor-api: '1'
      io.balena.features.balena-api: '1'
      io.balena.update.strategy: hand-over

And the console reads this. 

X.Org X Server 1.20.4
21.08.19 18:43:53 (-0400) X Protocol Version 11, Revision 0
21.08.19 18:43:53 (-0400) Build Operating System: Linux 4.15.0-48-generic armv8l Raspbian
21.08.19 18:43:53 (-0400) Current Operating System: Linux 8955240 4.14.98 #1 SMP Mon Jun 17 13:13:40 UTC 2019 armv7l
21.08.19 18:43:53 (-0400) Kernel command line: 8250.nr_uarts=0 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=800 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3f000000 vc_mem.mem_size=0x3f600000 dwc_otg.lpm_enable=0 console=null rootfstype=ext4 rootwait vt.global_cursor_default=0 root=PARTUUID=cf17c89d-03 rootwait
21.08.19 18:43:53 (-0400) Build Date: 05 June 2019 12:49:54PM
21.08.19 18:43:53 (-0400) xorg-server 2:1.20.4-1+rpt1 (https://www.debian.org/support) 
21.08.19 18:43:53 (-0400) Current version of pixman: 0.36.0
21.08.19 18:43:53 (-0400) Before reporting problems, check http://wiki.x.org
21.08.19 18:43:53 (-0400) to make sure that you have the latest version.
21.08.19 18:43:53 (-0400) Markers: (--) probed, (**) from config file, (==) default setting,
21.08.19 18:43:53 (-0400) (++) from command line, (!!) notice, (II) informational,
21.08.19 18:43:53 (-0400) (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
21.08.19 18:43:53 (-0400) (==) Log file: "/var/log/Xorg.0.log", Time: Wed Aug 21 22:43:53 2019
21.08.19 18:43:53 (-0400) (==) Using system config directory "/usr/share/X11/xorg.conf.d"
21.08.19 18:44:02 (-0400) [44:0821/224402.593135:ERROR:bus.cc(422)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
21.08.19 18:44:02 (-0400) [44:0821/224402.616763:WARNING:audio_manager.cc(293)] Multiple instances of AudioManager detected
21.08.19 18:44:02 (-0400) [44:0821/224402.616905:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
21.08.19 18:44:02 (-0400) [44:0821/224402.746103:ERROR:bus.cc(422)] Failed to connect to the bus: /usr/bin/dbus-launch terminated abnormally without any error message

```

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [August 23, 2019, 3:58pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/14 "2019-08-23T15:58:09Z")

</div>

Hello @mowi22 .  
The error is `Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory`  
The bus address seems incorrect.  
Do you have an `ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket` line in your Dockerfile?

---

<div class="post-metadata">

**Author:** ![mowi22](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mowi22/32/2416_2.png) [@mowi22](https://forums.balena.io/u/mowi22)\
**Post date:** [August 23, 2019, 4:54pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/16 "2019-08-23T16:54:24Z")

</div>

Ah, thanks, no, I’ve just added that to the dockerfile, but I’m still getting  
`Failed to connect to the bus: /usr/bin/dbus-launch terminated abnormally without any error message`

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [August 23, 2019, 5:07pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/17 "2019-08-23T17:07:00Z")

</div>

Can you please share your Dockerfile?

---

<div class="post-metadata">

**Author:** ![mowi22](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mowi22/32/2416_2.png) [@mowi22](https://forums.balena.io/u/mowi22)\
**Post date:** [August 23, 2019, 5:12pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/18 "2019-08-23T17:12:02Z")

</div>

```auto
# Build stage
##
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:10-build as build

EXPOSE 8080 5858

# Move to app dir
WORKDIR /usr/src/app

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
  apt-utils \
  clang \
  libxcb-image0 \
  libxcb-util0 \
  xdg-utils \
  network-manager \
  libdbus-1-dev \
  libgtk2.0-dev \
  libnotify-dev \
  libgnome-keyring-dev \
  libgconf2-dev \
  libasound2-dev \
  libcap-dev \
  libcups2-dev \
  libxtst-dev \
  libxss1 \
  libnss3-dev \
  libsmbclient \
  libssh-4 \
  libexpat-dev 

# Move package.json to filesystem
COPY ./app/package.json .

# Install npm modules for the application
RUN JOBS=MAX rm -rf node_modules && npm install --unsafe-perm --production && npm cache clean --force\
    && node_modules/.bin/electron-rebuild

###
# Runtime
##
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:10-run

# Move to app dir
WORKDIR /usr/src/app

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
  xserver-xorg-core \
  xserver-xorg-input-all \
  xserver-xorg-video-fbdev \
  xorg \
  libxcb-image0 \
  libxcb-util0 \
  python3-dbus \
  network-manager \
  xdg-utils \
  libdbus-1-3 \
  libgtk2.0 \
  libnotify4 \
  libgnome-keyring0 \
  libgconf-2-4 \
  libasound2 \
  libcap2 \
  libcups2 \
  libxtst6 \
  libxss1 \
  libnss3 \
  libsmbclient \
  libssh-4 \
  fbset \
  libexpat1 

RUN apt-get update

RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
  && echo "" >> /etc/X11/xinit/xserverrc \
  && echo 'exec /usr/bin/X -s 0 dpms -nocursor -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Move app to filesystem
COPY ./app ./

# Copy the modules from the build step
COPY --from=build /usr/src/app/node_modules ./node_modules

# Build react app
RUN JOBS=MAX npm run build

## uncomment if you want systemd
ENV INITSYSTEM on

ENV UDEV=1

ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

# Start app
CMD ["bash", "/usr/src/app/start.sh"]
```

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [August 23, 2019, 5:21pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/19 "2019-08-23T17:21:45Z")

</div>

You may need to install the `dbus-x11` package.

---

<div class="post-metadata">

**Author:** ![mowi22](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mowi22/32/2416_2.png) [@mowi22](https://forums.balena.io/u/mowi22)\
**Post date:** [August 24, 2019, 9:09pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/21 "2019-08-24T21:09:31Z")

</div>

That did it. Thanks!

---

<div class="post-metadata">

**Author:** ![cnr](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@cnr](https://forums.balena.io/u/cnr)\
**Post date:** [October 3, 2019, 9:16pm UTC](https://forums.balena.io/t/dbus-failed-to-connect-to-socket-host-run-dbus-system/3107/23 "2019-10-03T21:16:07Z")

</div>

Also got this error

```bash
$ DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
  dbus-send \
  --system \
  --print-reply \
  --reply-timeout=2000 \
  --type=method_call \
  --dest=org.freedesktop.timedate1 \
  /org/freedesktop/timedate1 \
  org.freedesktop.DBus.Properties.GetAll \
  string:"org.freedesktop.timedate1"
Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

```

I am not using a multi-container setup, however by adding the [`io.balena.features.dbus` label](https://www.balena.io/docs/learn/develop/multicontainer/#labels) to my container I was able to get `dbus-x11` and `dbus` to work inside my Ubuntu 18 container.

Adding here in case it helps someone else.
