Is it possible to access a hardware device with a

2020-08-13 06:14发布

问题:

Recently, a native Docker client for Windows was released (>= Windows 7).

I wonder: is it possible to forward access to physical devices, running Windows as host?

With a *nix host, this seems to be possible with the following syntax:

docker run -t -i --device=/dev/ttyUSB0 ubuntu bash

(as proposed here) which would forward the USB device /dev/ttyUSB0 on a *nix system to the docker image.

A description of the --device flag can be found in the docker docs.

What would be the syntax for a Windows host?

回答1:

Windows USB devices are not currently available to Docker containers run with Docker for Windows.

Answered by a Docker staff member on the 7th of July 2017 in the Docker forum.

https://forums.docker.com/t/exposing-docker-to-usb-device-in-windows-10-with-docker-toolbox/29290/3

This answer is likely to get outdated in some time, provided they will allow for this feature somehow.



回答2:

This is a bad practice as it goes against the design philosophy of containers.

If you find yourself needing access to a hardware device, it's better to consider full virtualization such as VMware, Hyper-V, KVM/QEMU, Xen and so on.

However, the "proper" way is to design your system so that hardware is abstracted into a network service. In this way, you deploy the service to physical machines to which the hardware is attached, and call them over the network. I don't know if this is possible in your case, but such decoupling provides a significant architectural advantage.