LoginSignup
0
0

Ubuntuイメージのコンテナ内でbluetoothctlが使えない

Posted at

この記事は, 大阪工業大学 Advent Calendar 2023の5日目の記事です.

動作環境

Ubuntu 22.04
Bluez 5.64

何があったのか

Ubuntuイメージのコンテナ内でbluetoothctlコマンドを実行したときにエラーが発生しました

error message
$ bluetoothctl
Waiting to connect to bluetoothd...dbus[605]: arguments to dbus_connection_get_object_path_data() were incorrect, assertion "connection != NULL" failed in file ../../../dbus/dbus-connection.c line 5905.
This is normally a bug in some application using the D-Bus library.

  D-Bus not built with -rdynamic so unable to print a backtrace
Aborted (core dumped)

原因

エラーメッセージを見る感じD-Bus関連のエラーみたいです.
公式のUbuntuイメージでは最小限の構成で環境が作成されるので,デフォルトではD-Bus関連のサービスが含まれていない,または無効化されているのが原因と考えられます.

D-Bus

D-Busとは,アプリケーション間の通信をするためのメッセージバスシステムで,アプリケーションがシステムサービスや他のアプリケーションと通信するための仕組みを提供しています.
身近な例だと,デスクトップに表示される通知の送受信やBluetoothデバイスとの通信などがあります.

解決策

コンテナ内でD-Busが動くようにします.
dockerのコンテナ作成時にD-Bus用のソケットファイルをマウントすることで,コンテナ内のプロセスがホストのD-Busシステムにアクセスできるようになります.
D-Busのソケットファイルは/var/run/dbus/system_bus_socketにあるので,これをマウントします.

bash
docker run -it --privileged -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro ubuntu:22.04 bash

この時,--privilegedオプションを付けてコンテナにホストマシンのほぼすべての権限を付与しないとBluetoothctlが使えませんでした.
このオプションはセキュリティリスクを高めるので使用する際は注意してください.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0