16

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pascal
  • 2,197
  • 3
  • 24
  • 34

2 Answers2

4

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dbalakirev
  • 1,918
  • 3
  • 20
  • 31
0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jurez
  • 4,436
  • 2
  • 12
  • 20
  • 8
    Can't see why it would be against the philosophy. In my understanding a container provides a service within a defined environment. If the service requires hardware, it would be natural for me to put it in that environment. Of course such a service could run only once. For example providing the fill level of a coffee machine. In that case the container connecting to the machine decouples the possible collection of containers from the hardware that provides the fill level. – Pascal Aug 25 '17 at 08:05
  • Docker is essentially a chroot jail on steroids. It shares the kernel with the host, and with it, the hardware devices. This is the fundamental difference between containers and virtualization. You could certainly argue that docker should be hardware-agnostic (I'm not discouraging you to try), but I'm afraid this mixing of architectural layers is likely to cause you a headache. YMMV. – jurez Aug 26 '17 at 13:59
  • Docker is absolutely not "a chroot jail on steroids" it's way more than that, check projects like balena engine and how docker is used in this case. Hardware access is essential in many cases. I think the design philosophy is also flexibility which it offers in this case. Docker is used here to deploy software easily while being supervised and easy to update any time on remote devices you don't have access to physically.Docker (with the help of drivers) also supports full virtualization for containers. – Tom Dec 18 '20 at 12:44
  • @TomS. I used this as a metaphor to help understand the concept. But in the same sense Docker is also not "a tool to deploy software easily while being supervised and easy to update any time on remote devices you don't have access to physically." The only thing that Docker actually is is "a piece of code that uses Linux control groups and other kernel features to achieve isolation of processes". How (and for what) you use it is up to your imagination, but the code itself will determine the limits of what is possible and what is not. – jurez Dec 18 '20 at 18:11