如何在 Docker 中使用蓝牙?

ise*_*xxx 5 ubuntu bluetooth bluetooth-lowenergy bluez docker

我在 Windows/MacOS 上的 Docker 中有一个 Ubuntu 容器。

\n

我想用来bluez与容器中的 BLE 外设进行通信。

\n

service bluetooth startbluetoothd、 以及hciconfig全部无法扫描通信。

\n

请告诉我是否有任何方法可以做到这一点或了解如何做到这一点。

\n

环境:

\n
Windows 10 Home -> Docker v20.10.14 -> Ubuntu 22.04 LTS (Jammy Jellyfish)\nMacOS Monterey 12.3.1 ->  Docker v20.10.12 -> Ubuntu 22.04.4 LTS\n
Run Code Online (Sandbox Code Playgroud)\n

我在 Windows/MacOS 上做了什么:

\n
# docker run --name <container> --net=host --privileged -it ubuntu /bin/bash\n
Run Code Online (Sandbox Code Playgroud)\n

我在容器方面做了什么:

\n
# apt-get update \n# apt-get upgrade -y\n# apt-get install -y dbus bluetooth bluez bluez-firmware\n# service dbus start \n
Run Code Online (Sandbox Code Playgroud)\n

故障一:bluetooth启动后未激活

\n
# service bluetooth start\n * Starting bluetooth\n# service bluetooth status\n * bluetooth is not running\n
Run Code Online (Sandbox Code Playgroud)\n

故障二:bluetoothd无法访问接口

\n
# bluetoothd -dn\nbluetoothd[2292]: Bluetooth daemon 5.64\nbluetoothd[2292]: src/main.c:parse_config() parsing /etc/bluetooth/main.conf\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cDiscoverableTimeout\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cAlwaysPairable\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cPairableTimeout\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cPrivacy\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cJustWorksRepairing\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cTemporaryTimeout\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cName\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cClass\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cDeviceID\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cReverseServiceDiscovery\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have key \xe2\x80\x9cRemoteNameRequestRetryDelay\xe2\x80\x9d in group \xe2\x80\x9cGeneral\xe2\x80\x9d\nbluetoothd[2292]: src/main.c:parse_config() Key file does not have group \xe2\x80\x9cGATT\xe2\x80\x9d\n\xef\xbc\x88...\xef\xbc\x89\nbluetoothd[2292]: src/main.c:parse_mode_config() Key file does not have group \xe2\x80\x9cLE\xe2\x80\x9d\nbluetoothd[2292]: src/adapter.c:adapter_init() Failed to access management interface\nbluetoothd[2292]: src/main.c:main() Adapter handling initialization failed\n
Run Code Online (Sandbox Code Playgroud)\n

故障3:hciconfig无法打开socket

\n
root@docker-desktop:/# hciconfig\nCan\'t open HCI socket.: Address family not supported by protocol\nroot@docker-desktop:/# hcitool scan\nDevice is not available: Address family not supported by protocol\nroot@docker-desktop:/# hcitool dev\nDevices:\n
Run Code Online (Sandbox Code Playgroud)\n

故障4:无法添加btusb模块

\n
# lsmod\nModule                  Size  Used by\n# modprobe btusb\n\xef\xbc\x88Windows\xef\xbc\x89\nmodprobe: FATAL: Module btusb not found in directory /lib/modules/5.10.16.3-microsoft-standard-WSL2\n\xef\xbc\x88MacOS\xef\xbc\x89\nmodprobe: FATAL: Module btusb not found in directory /lib/modules/5.10.76-linuxkit\n
Run Code Online (Sandbox Code Playgroud)\n

参考网址:

\n\n