Python dbus not included in new balenalib images?

Hello,
I want to move from old resin images to balenalib. Try to migrate from python3.6.1 image to balenalib/raspberry-pi-python:3.6.6

import dbus not working anymore.

Here is a list of modules available:

help(“modules”)

Please wait a moment while I gather a list of all available modules…

future abc html selectors
_ast aifc http setuptools
_asyncio antigravity idlelib shelve
_bisect argparse imaplib shlex
_blake2 array imghdr shutil
_bootlocale ast imp signal
_bz2 asynchat importlib site
_codecs asyncio inspect smtpd
_codecs_cn asyncore io smtplib
_codecs_hk atexit ipaddress sndhdr
_codecs_iso2022 audioop itertools socket
_codecs_jp base64 json socketserver
_codecs_kr bdb keyword spwd
_codecs_tw binascii lib2to3 sqlite3
_collections binhex linecache sre_compile
_collections_abc bisect locale sre_constants
_compat_pickle builtins logging sre_parse
_compression bz2 lzma ssl
_crypt cProfile macpath stat
_csv calendar macurl2path statistics
_ctypes cgi mailbox string
_ctypes_test cgitb mailcap stringprep
_curses chunk marshal struct
_curses_panel cmath math subprocess
_datetime cmd mimetypes sunau
_decimal code mmap symbol
_dummy_thread codecs modulefinder symtable
_elementtree codeop multiprocessing sys
_functools collections netrc sysconfig
_hashlib colorsys nis syslog
_heapq compileall nntplib tabnanny
_imp concurrent ntpath tarfile
_io configparser nturl2path telnetlib
_json contextlib numbers tempfile
_locale copy opcode termios
_lsprof copyreg operator test
_lzma crypt optparse textwrap
_markupbase csv os this
_md5 ctypes ossaudiodev threading
_multibytecodec curses parser time
_multiprocessing datetime pathlib timeit
_opcode dbm pdb tkinter
_operator debconf pickle token
_osx_support decimal pickletools tokenize
_pickle difflib pip trace
_posixsubprocess dis pipes traceback
_pydecimal distutils pkg_resources tracemalloc
_pyio doctest pkgutil tty
_random dummy_threading platform turtle
_sha1 easy_install plistlib turtledemo
_sha256 email poplib types
_sha3 encodings posix typing
_sha512 ensurepip posixpath unicodedata
_signal enum pprint unittest
_sitebuiltins errno profile urllib
_socket faulthandler pstats uu
_sqlite3 fcntl pty uuid
_sre filecmp pwd venv
_ssl fileinput py_compile warnings
_stat fnmatch pyclbr wave
_string formatter pydoc weakref
_strptime fractions pydoc_data webbrowser
_struct ftplib pyexpat wsgiref
_symtable functools queue xdrlib
_sysconfigdata_m_linux_arm-linux-gnueabihf gc quopri xml
_testbuffer genericpath random xmlrpc
_testcapi getopt re xxlimited
_testimportmultiple getpass readline xxsubtype
_testmultiphase gettext reprlib zipapp
_thread glob resource zipfile
_threading_local grp rlcompleter zipimport
_tracemalloc gzip runpy zlib
_warnings hashlib sched
_weakref heapq secrets
_weakrefset hmac select

Thank you for reporting this ! Our images team is pinged on this thread and will take a look :slight_smile:

@letrich, as mentioned in our blog post https://www.balena.io/blog/new-year-new-balena-base-images/, run variant is the default in balenalib base images which only contains some runtime essentials packages (it’s quite the same as slim variant in resin base images) so dbus it not there.

You can change to build variant which has dbus installed (balenalib/raspberry-pi-python:3.6.6-build) or manually install it. This is how we install dbus in our base images https://github.com/balena-io-library/base-images/blob/master/balena-base-images/python/aarch64/debian/jessie/3.6.6/build/Dockerfile#L57-L69

1 Like

Hi @nghiant2710
Thanks for your advice! Seems now it installed.
But I have another error in my container:

ERROR: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

I use balenalib/rpi-raspbian-python:3.6.6-build

Before run app I make export:

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

All was working previously on the single-container app with resin image.

docker-compose.yml (info for only this particular container):

version: ‘2’
volumes:
resin-data:
services:
core:
build: ./core
privileged: true
volumes:
- ‘resin-data:/data’
restart: always
labels:
io.balena.features.dbus: ‘1’
io.balena.features.supervisor-api: ‘1’
expose:
- “5000”
ports:
- “80:5000”

Also no /host folder in the container according to ls /host command

Can you please confirm that that’s the base image you are using? Or is it a typo? I cannot see one like that, just balenalib/raspberry-pi-python:3.6.6-build.

I’ve tried a small project, and dbus works just fine. I used the following files:

docker-compose.yml:

version: '2'

volumes:
  resin-data:

services:
  core:
    build: ./core
    privileged: true
    volumes:
    - 'resin-data:/data'
    restart: always
    labels:
      io.balena.features.dbus: '1'
      io.balena.features.supervisor-api: '1'
    expose:
      - "5000"
    ports:
      - "80:5000"

the core/Dockerfile:

FROM balenalib/raspberry-pi-python:3.6.6-run

RUN install_packages dbus
COPY start.sh ./

CMD ["bash", "start.sh"]

and core/start.sh:

#!/bin/bash

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

while : ; do
  dbus-send --system --print-reply \
            --dest=org.freedesktop.NetworkManager \
            /org/freedesktop/NetworkManager \
            org.freedesktop.DBus.Properties.Get \
            string:"org.freedesktop.NetworkManager" \
            string:"ActiveConnections"
  sleep 10
done

and I’ve getting fine:

18.01.19 18:30:18 (+0000)  core  method return time=1547836218.960517 sender=:1.5 -> destination=:1.53 serial=6214 reply_serial=2
18.01.19 18:30:18 (+0000)  core     variant       array [
18.01.19 18:30:18 (+0000)  core           object path "/org/freedesktop/NetworkManager/ActiveConnection/2"
18.01.19 18:30:18 (+0000)  core           object path "/org/freedesktop/NetworkManager/ActiveConnection/1"
18.01.19 18:30:18 (+0000)  core        ]

Just some notes: I used the balenalib/raspberry-pi-python:3.6.6-run image, and install the dbus package manually, since likely you want the run image later anyway, as it’s much smaller.

Do you see any difference between what we are doing here, and what you are doing? I see the quote marks in your code being “wrong” (should be ', and not ), but maybe that’s just a pasting issue, and the actual docker-compose.yml is using the right quotes.

Hi @imrehg,
I use balenalib/raspberry-pi-python:3.6.6-build by @nghiant2710 advice.
Seems labels dont work at all in this build.

Hi @letrich, I think now the problem might not be the base image but the OS version you might be using. What balenaOS (or resinOS) version are you using? In older versions (from before our company rename), you should use a io.resin.features.dbus label instead.

I use Resin OS 2.15.1+rev2.
Will try to update OS on this device

I have updated OS and all works now
Thank you!

Thanks for letting us know :slight_smile: