Accessing Bluetooth dongle from inside Docker?

前端 未结 4 753
逝去的感伤
逝去的感伤 2021-02-08 02:29

Is it possible to use a bluetooth (BLE in my case) dongle inside of a docker container?

On my host machine:

$ hcitool dev
    Devices:
       hci0   5C:F         


        
相关标签:
4条回答
  • 2021-02-08 02:39

    I can confirm that what OlivierM wrote is working on me. Spent some time on Raspberry Pi 3B+ and its built-in bluetooth.

    Dockerfile:

    FROM python:3.7
    
    RUN apt-get update
    
    RUN apt-get install -y bluez bluetooth
    
    ENTRYPOINT sh docker_entrypoint.sh
    

    and entrypoint:

    #!/bin/bash
    
    service dbus start
    bluetoothd &
    
    /bin/bash
    

    sudo killall -9 bluetoothd is needed on host machine before before starting the container:

    docker run --rm --net=host --privileged -it myimage:mytag
    
    0 讨论(0)
  • 2021-02-08 02:41

    Try this:

    sudo docker run --net=host --privileged -i -t ubuntu /bin/bash

    0 讨论(0)
  • 2021-02-08 02:45

    If you want to run bluez from a docker (and not only expose hci adapter) you need:

    • To start your docker with sudo docker run --privileged -i -t your_image_name /bin/bash
    • Make sure bluez is not running on your host. In my case I add to kill bluez (killall -9 bluetoothd) (and not stopped it properly as it will power down my bluetooth adapter and will not exposed it into the docker)
    • In your docker entrypoint, you will need to start dbus (/etc/init.d/dbus start) and bluez (/usr/libexec/bluetooth/bluetoothd --debug &)
    0 讨论(0)
  • 2021-02-08 02:56

    With help from Docker Community, I have Successfully Started DBus/Bluetooth Services inside docker container and scan bluetooth devices by adding --cap-add=SYS_ADMIN, --cap-add=NET_ADMIN and --net=host flags/permission

    docker run --cap-add=SYS_ADMIN --cap-add=NET_ADMIN --net=host -it debian:jessie

    Now just looking to start bluetooth service by "Not sharing the Host Networking Namespace" (customising --net=host to private network)

    If somebody got any Clue, that would be helpful. Thanks.

    0 讨论(0)
提交回复
热议问题