Pass USB device into a Docker Windows Container - windows

I'm on Windows 10 using Docker for Windows. Also, I have a container which originates FROM microsoft/windowsservercore. I have an USB device attached and want to pass it to that container.
What I found so far:
Under Linux you got --device=/dev/.., but how can I accomplish this under Windows?
Michael Friis wrote on 2017-07-07 that this is currently not possible. However, this comment states that it is.
So my questions are:
Is it currently possible to pass an USB device from a Windows Host into a Windows Docker container?
If yes, what is the correct syntax?
If not, when approximately can we expect this feature?

You cannot directly pass USB to the container. Either you have to run Docker as a VM or use USB/IP (where the USB data is transferred as IP packets). But there will be a delay in the second method.

I spent a day trying to figure out this problem, unfortunately there is no way to passthru USB devices to Windows containers as for now (Sep 2022).
Hyper-V doesn't support USB Passthru per se. While USB-IP seems like a viable solution, it requires installing custom drivers (usually self-signed), which is not support with Windows containers.

USB passthrough is currently not supported with Windows for Docker as of November 2017:
Docker for Windows USB Support

There is a way to pass USB through to Docker for Desktop running on windows. If the docker engine is running using WSL2 (Settings -> General -> Use the WSL 2 based engine) then you can attach a usb device using the usbipd libraries.
Details on USBIPD library and download:
https://learn.microsoft.com/en-us/windows/wsl/connect-usb
I went into Command Prompt and typed in:
usbipd wsl list
Found the USB device that I wanted available in my docker container and then attached it in usbipd using the command:
usbipd wsl attach --busid <bus-id>
In the docker compose script I have:
devices:
- /dev/ttyUSB0:/dev/ttyUSB0
Which is where the usb device is being seen when I go into the container and go to /dev I see that ttyUSB0 is listed.
I can now use that USB device.. the trick is that the device needs to be attached using the usbipd command before the container starts or you will need to restart the containers for the container OS to see everything.
If you have that devices statement in your compose you might fine to attach and detach using usbipd and it just works since it would take the ttyUSB0 each time.

Related

Windows 10 reading usb data from windows docker container

I have a program that reads some data from USB, I would be running it as docker container (windows 10) on windows 10, I would like to know if it is possible to read the usb data when I run the program as container (windows container) where base operating system is windows 10.
Regards,
Amit
If a key goal of the process is to access hardware devices, it’s best to not run in a Docker container, which intentionally tries to hide details of the underlying hardware from you. That’s doubly true if you need to use Docker Toolbox, which adds an additional layer of virtual machine.
In addition to USB devices, I’d also avoid Docker if your goals include installing software on the host, reconfiguring or monitoring the host’s network interfaces, or accessing other hardware devices like sound or display configuration.

How to view USB devices in a Docker container, Windows Hyper-V host?

I'm trying to do this: Docker - any way to give access to host USB or serial device?
I want to develop an application with Ionic but I cannot see my device (or any usb, lsusb) running adb devices.
Do I need to map a USB folder to the container (like -v /dev/bus/usb:/dev/bus/usb)?
But how do I do that on Windows?
afaik Hyper-V cannot "handle"/forward/map USB devices. Thus my guess is it will not work in containers either.

Accessing USB webcam hosted on OS X from a Docker container

Is it possible to access a USB camera (e.g Logitech c270) from a Docker container?
The camera is connected to a Mac host via a USB port.
Even when running the container with --privileged, i could not find the device (e.g /dev/video0 file does not exist).
Thanks
The default docker-machine creates a virtual machine with official boot2docker.iso. And this slim distro doesn't support USB video device. When you attach the USB device to the virtual machine, the kernel can't do anything without the right driver. So, you won't see any video capturing device, such as /dev/video0.
TL;DR
I've compiled a customized boot2docker.iso which ships uvcvideo driver. Use this one to create you docker machine.
docker-machine create -d virtualbox --virtualbox-boot2docker-url https://github.com/Alexoner/boot2docker/releases/download/v17.06.0-ce-usb-rc5/boot2docker.iso default
Then install the VirtualBox extension, attach the webcam device, you are good to go!
Reference
Attach webcam: https://www.virtualbox.org/manual/ch09.html#webcam-passthrough

Is it possible to access a hardware device with a Docker image under Windows?

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?
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.
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.

How to deploy Windows 10 IoT (Rasp Pi image) as a Virtual Machine

Is it possible to deploy Windows 10 IoT (Rasp Pi image) as a Virtual Machine using VirtualBox or VMWare Player?
I need for a testing lab a network of three to five Windows 10 IoT devices. A virtual cluster would be perfect. My Google- and Bing-based research failed.
The problem could be either the non-ISO disk image file format or the non-x86 architecture of the operating system, couldn't it?
The easiest way I found is downloading Windows 10 IoT Core for MinnowBoard MAX
(here: http://go.microsoft.com/fwlink/?LinkId=691712). This MinnowBoard is x86-based and the image comes in a .iso file. I know the OP was specific about being a Rasp Pi image, but I don't really see the difference if we're just trying to use a hypervisor. Afterwards, you may just follow this tutorial: http://www.newventuresoftware.com/blog/running-windows-10-iot-core-in-a-virtual-machine
It's very simple and straight-forward, and it works with VirtualBox.
Based on #makoshichi's links here's the steps that worked for me:
Download MinnowBoard MAX IoT Core from microsoft, and install
Run ImgMount tool as Admin to mount "C:\Program Files (x86)\Microsoft IoT\FFU\MinnowBoardMax\flash.ffu"
Detach the VHD from Disk Management (in Computer Management), move the resultant .vhd file (that it informs you of on detach) to a location of your choice
Create, but don't launch, a new Virtual Machine in VirtualBox (expert mode) as Windows 32-bit, using an "existing virtual hard disk file" - the one you just moved
Goto device Settings->System and click Enable EFI (special OSes only)
Goto device Settings->Network and select Bridged Adapater
That's it - Run your virtual machine and be a happy Thing of the Internet, or something like that.
This is my short version of this wonderful post by Yavor Ivanov.
The QEMU emulator may do it, it will boot the image file directly. you may need to expand the ffu with dism first.
You don't have to fully install w10 preview: just boot the W10 real or virtual DVD and select to open a cmd box, from there you can run the updated dism command.iot w10 have no (direct) GUI, you must talk to the device via winrm and powershell
There is a good startup for you on
sourceforge
fc
https://github.com/0xabu/qemu/tree/raspi is a working way to run Windows 10 IoT on Qemu. It fully emulates a RPi2, except USB
Hi you could use the Raspberry Pi Simulator https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-raspberry-pi-web-simulator-get-started

Resources