简体   繁体   English

docker 中的蓝牙用于 windows 主机

[英]bluetooth in docker for windows host

My docker version is:我的 docker 版本是:

docker --version

Docker version 20.10.2, build 2291f61

My windows version is:我的 windows 版本是:

systeminfo

Nom du système d’exploitation:              Microsoft Windows 10 Professionnel
Version du système:                         10.0.17763 N/A version 17763
Type du système:                            x64-based PC

My Dockerfile is:我的 Dockerfile 是:

FROM ubuntu:21.04
RUN apt update
RUN apt-get install -y bluez bluetooth usbutils

When I run the following command, I start the 'bluetooth_in_docker' container:当我运行以下命令时,我启动了“bluetooth_in_docker”容器:

docker build -t bluetooth_in_docker . & docker run --privileged --net=host -it bluetooth_in_docker bash

Inside the container when I run the following, I get an error:当我运行以下命令时,在容器内部出现错误:

hciconfig dev

Can't open HCI socket.: Address family not supported by protocol

I got it working on Windows from inside WSL2, but it takes a lot of steps.我从 WSL2 内部让它在 Windows 上工作,但它需要很多步骤。

  • Follow https://github.com/dorssel/usbipd-win/discussions/310 to get your bluetooth working inside WSL2.按照https://github.com/dorssel/usbipd-win/discussions/310让你的蓝牙在 WSL2 中工作。 Verify that you can scan for bluetooth devices inside your WSL2 distro.确认您可以在 WSL2 发行版中扫描蓝牙设备。

  • modify your dockerfile to install bluetooth as you did (bluez and usb-utils might not be needed)修改您的 dockerfile 以像您一样安装bluetooth (可能不需要 bluez 和 usb-utils)

  • Now there are 2 options.现在有2个选项。 First option shares bluetooth with container.第一个选项与容器共享蓝牙。 Second option gives container exclusive control.第二个选项赋予容器独占控制权。

    1. Sharing bluetooth between the host and the container is possible by making a volume mount of /var/run/dbus and running it with --privileged :通过挂载 /var/run/dbus 的卷并使用--privileged运行它,可以在主机和容器之间共享蓝牙:

       docker run -v /var/run/dbus/:/var/run/dbus/:z --privileged {containerImage}

      Make sure that the dbus and bluetooth services are working in your host when running the container this way.以这种方式运行容器时,请确保 dbus 和蓝牙服务在您的主机中正常工作。

    2. Giving the container exclusive control: in WSL2 (the host), run a docker container according to https://stackoverflow.com/a/64126744/1114918赋予容器独占控制权:在 WSL2(主机)中,根据https://stackoverflow.com/a/64126744/1114918运行一个 docker 容器

    • run sudo service bluetooth stop to make your bluetooth not "claimed" by the host (the linked answer uses killall , I think sudo service... stop is cleaner)运行sudo service bluetooth stop使您的蓝牙不被主机“占用”(链接的答案使用killall ,我认为sudo service... stop更干净)
    • use a sh script to start dbus and bluetooth inside the container使用 sh 脚本在容器内启动 dbus 和蓝牙
    • run the container using使用运行容器
      docker run --rm -.net=host --privileged myimage:mytag

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM