docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.87k stars 291 forks source link

Bluetooth Dongle not working with WSL #14284

Open SirLouen opened 2 months ago

SirLouen commented 2 months ago

Description

Theoretically the solution was already there, someone did it and documented

But I've found that integrating a Bluetooth Dongle with Windows is not so trivial as commented there. Maybe it is because the stack has upgraded and since this is a 2 year old post, perhaps some new flaws have arisen.

I've tried to implement most ideas I've read both here and Github. Most questions regarding this topic are based on a Linux host (like Raspberry Pi), not over Windows/WSL. For example this: https://stackoverflow.com/questions/28868393/accessing-bluetooth-dongle-from-inside-docker/64126744

I've read plenty of posts in Github being this one of the most thorough.

Now I'm going to describe and reproduce the steps taking based on the suggesting and how it's not working despite all ideas I've read so far.

Reproduce

  1. First making it work in the WSL2. After setting up USBIPD and everything, everything is perfectly fine working in the WSL host:
# 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
  1. Preparing the Docker image:

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 Stopping Bluetooth service in the WSL host sudo service bluetooth stop

$ bluetoothctl
Waiting to connect to bluetoothd...
$ sudo hcitool lescan
Could not open device: No such device

2.4. Build the image and start it with:

docker -t myimage .
docker run --rm --net=host --privileged -it myimage

This is the full setup recommended in 100% of the places I've seen.

Expected behavior

Theoretically now that the WSL host is not serving Bluetooth it should work straight on the docker image:

First, the device is there:

# 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

Second, bluetoothd, despite being run in the entrypoint is not actually running:

# 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 | 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

I also tried running the image sharing system bus socket, instead of using the --net=host thing with:

$ 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 

But the same results as the ones above.

docker version

Client:
 Version:           27.1.1
 API version:       1.46
 Go version:        go1.21.12
 Git commit:        6312585
 Built:             Tue Jul 23 19:55:52 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Desktop  ()
 Engine:
  Version:          27.1.1
  API version:      1.46 (minimum version 1.24)
  Go version:       go1.21.12
  Git commit:       cc13f95
  Built:            Tue Jul 23 19:57:19 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.19
  GitCommit:        2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc:
  Version:          1.7.19
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    24.0.7
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.16.1-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.1-desktop.1
    Path:     /usr/local/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.34
    Path:     /usr/local/lib/docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /usr/local/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.25
    Path:     /usr/local/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /usr/local/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.11.0
    Path:     /usr/local/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 7
 Server Version: 27.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 6.6.36.3-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 30.94GiB
 Name: docker-desktop
 ID: c9e17826-fa03-4f01-87c9-aa8db90f5393
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///var/run/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

Diagnostics ID

77F07B67-A67F-4B23-86A1-9FBE325F6292/20240825181036

Additional Info

Although everything seems to be perfectly in order hardware-wise, it's not within the docker container. I have spent countless hours reading posts unsuccessfully, and now I'm giving up, at this point I'm completely lost, and have not found any more references to keep moving forward.

yaplej commented 2 weeks ago

I am also unable to get a bluetooth adapter to work in Docker with WSL2.

uname -r
5.15.153.1-microsoft-standard-WSL2

Trying to load the development environment for Home Assistant and the particular integration I am testing requires a bluetooth connection to the hardware. So passing a dedicated USB bluetooth adapter seemed like the easiest solution but could not get it working because of this issue.

SirLouen commented 2 weeks ago

Trying to load the development environment for Home Assistant and the particular integration I am testing requires a bluetooth connection to the hardware. So passing a dedicated USB bluetooth adapter seemed like the easiest solution but could not get it working because of this issue.

Too bad that docker for windows is closed source, and they take 3 months to even triage the issues... Yes I'm in a similar situation, willing to test over WSL on my main windows computer, but I ended testing with a Raspberry PI over VNC, baremetal.

adamscybot commented 6 days ago

Please see my post here https://github.com/microsoft/WSL/issues/12234 about how I got BT working with a WSL-based devcontainer.

One critical difference I can see between my solution and what OP @SirLouen is trying, is I do not try to run bluetoothd inside of the container. Instead, you run all of that on the WSL host, and then you bind dbus to the container.

Though I note that you seem to have tried this as well, I wonder if it was on a clean container where the container itself didn't have dbus etc?

Theres a layer of abstraction in my solution in that I'm also dealin with home assistant and that uses devcontainer, which is a docker wrapper. But notice how the paths are bound in the above post.