Windows下Docker容器无法访问蓝牙适配器的技术求助
蓝牙适配器在WSL2 Docker容器中无法正常工作的问题
理论上已有成熟解决方案,但Windows系统下集成蓝牙适配器并不像旧帖描述的那样简单,推测是技术栈更新引发了新问题。尝试过多数基于Linux主机的方案,但WSL环境下的适配问题始终未解决。
环境栈
- WSL版本:2.3.14.0(未使用最新2.3.17,因蓝牙适配器需Kernel 6.6驱动,自定义内核会导致Docker Desktop异常)
- Kernel版本:6.6.36.3-1
- Docker Desktop:4.33.1
- Docker:27.1.1
- USBIPD:4.3.0
已执行步骤与验证结果
- WSL2中验证蓝牙功能正常:
配置USBIPD后,WSL可正常识别蓝牙适配器:
# lsusb Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 002: ID 10d7:b012 Actions general adapter Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ bluetoothctl Agent registered [CHG] Controller F4:4E:FC:8E:1A:30 Pairable: yes
$ hciconfig hc0 hci0: Type: Primary Bus: USB BD Address: F4:4E:FC:8E:1A:30 ACL MTU: 679:6 SCO MTU: 240:20 UP RUNNING RX bytes:1825 acl:0 sco:0 events:110 errors:0 TX bytes:4419 acl:0 sco:0 commands:97 errors:0
- 准备Docker镜像与容器:
2.1 Dockerfile:
FROM ubuntu:latest RUN apt-get update RUN apt-get install -y bluez bluetooth usbutils COPY docker_entrypoint.sh /usr/src/app/docker_entrypoint.sh ENTRYPOINT sh /usr/src/app/docker_entrypoint.sh
2.2 docker_entrypoint.sh:
#!/bin/bash service dbus start bluetoothd & /bin/bash
2.3 停止WSL主机蓝牙服务并验证:
$ sudo service bluetooth stop
验证服务已停止:
$ bluetoothctl Waiting to connect to bluetoothd...
$ sudo hcitool lescan Could not open device: No such device
2.4 构建镜像并启动容器:
docker build -t myimage . docker run --rm --net=host --privileged -it myimage
容器内遇到的问题
- 可识别蓝牙设备:
# lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 002: ID 10d7:b012 Actions general adapter Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
- bluetoothd无法正常运行:
# service bluetooth status * bluetooth is not running
# bluetoothd -n bluetoothd[65]: Bluetooth daemon 5.72 bluetoothd[65]: src/adapter.c:adapter_init() Failed to access management interface bluetoothd[65]: src/main.c:main() Adapter handling initialization failed
# hciconfig hc0 Can't open HCI socket.: Address family not supported by protocol
- 蓝牙模块已加载:
# lsmod | grep bluetooth bluetooth 741376 6 btrtl,btintel,btbcm,bnep,btusb ecdh_generic 12288 1 bluetooth
- dmesg日志:
# dmesg | grep Bluetooth [ 75.485496] Bluetooth: Core ver 2.22 [ 75.485527] Bluetooth: HCI device and connection manager initialized [ 75.485532] Bluetooth: HCI socket layer initialized [ 75.485534] Bluetooth: L2CAP socket layer initialized [ 75.485538] Bluetooth: SCO socket layer initialized [ 3675.898623] Bluetooth: BNEP (Ethernet Emulation) ver 1.3 [ 3675.898630] Bluetooth: BNEP socket layer initialized [ 3695.249669] Bluetooth: hci0: HCI Read Default Erroneous Data Reporting command is advertised, but not supported. [ 3695.249672] Bluetooth: hci0: HCI Read Transmit Power Level command is advertised, but not supported. [ 3695.249674] Bluetooth: hci0: HCI LE Set Random Private Address Timeout command is advertised, but not supported. [ 3695.364291] Bluetooth: MGMT ver 1.22
另外尝试过共享系统总线套接字启动容器(不使用--net=host参数):
$ docker run --rm -it -v /var/run/dbus/:/run/dbus/:z --privileged myimage * Removing stale PID file /var/run/dbus/pid. * Starting system message bus dbus
结果与上述问题完全一致。
硬件层面无异常,但容器内始终无法正常使用蓝牙,恳请提供解决方案。
内容的提问来源于stack exchange,提问作者SirLouen
相关产品推荐
相关产品推荐

