Docker - 一种访问主机 USB 或串行设备的方法? [英] Docker - a way to give access to a host USB or serial device?
问题描述
我上次检查时,Docker 没有任何方法可以让容器访问主机串行或 USB 端口.有没有允许这样做的技巧?
Last time I checked, Docker didn't have any means to give container access to host serial or USB port. Is there a trick which allows doing that?
推荐答案
有几个选项.您可以使用 --device
标志,用于在没有 --privileged
模式的情况下访问 USB 设备:
There are a couple of options. You can use the --device
flag that use can use to access USB devices without --privileged
mode:
docker run -t -i --device=/dev/ttyUSB0 ubuntu bash
或者,假设您的 USB 设备可在 /dev/bus/usb
中的主机上运行驱动程序等,您可以使用 特权模式 和 卷选项.例如:
Alternatively, assuming your USB device is available with drivers working, etc. on the host in /dev/bus/usb
, you can mount this in the container using privileged mode and the volumes option. For example:
docker run -t -i --privileged -v /dev/bus/usb:/dev/bus/usb ubuntu bash
请注意,顾名思义,--privileged
是 不安全,应小心处理.
Note that as the name implies, --privileged
is insecure and should be handled with care.
这篇关于Docker - 一种访问主机 USB 或串行设备的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!