Docker容器看不到串口设备

Docker container can't see a serial port device

我正在尝试 运行 一个 Docker 可以访问主机串口的容器。

这是我所做的:

我玩了很多不同的参数,但我还没有找到合适的:)

此外 --device 标志也不适合我,因为设备可能会重新连接并且名称可能与 /dev/tty.usbserial 不同。

您可以查看 Notification of new USB devices in docker container" (from Guido Diepen -- gdiepen) 中描述的脚本是否有帮助。

他也使用 --privileged 参数运行他的容器,以允许它访问设备。并且他在启动所述容器时使用参数 -v /dev/bus/usb:/dev/bus/usb 将主机目录 /dev/bus/usb 挂载到容器内的 /dev/bus/usb 目录。

该脚本同时使用 inotifywaitlsusb 来等待设备插入(拔出)并检查它是否是我们感兴趣的设备。

The inotifywait will keep on listening to inodes create/delete events under the dev/bus/usb directory and will execute commands whenever an inode corresponding to a relevant device has been just created.

另请参阅,一旦检测到插入的 USB 设备,How to get Bus and Device relationship for a /dev/ttyUSB(与 Docker 无关,但仍然相关)。

正如@pgayvallet on GitHub指出的那样:

As the daemon runs inside a VM in Docker Desktop, it is not possible to actually share a mac host device with the container inside the VM, and this will most definitely never be possible.