10

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:

  1. Is it currently possible to pass an USB device from a Windows Host into a Windows Docker container?
  2. If yes, what is the correct syntax?
  3. If not, when approximately can we expect this feature?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JustCoding
  • 399
  • 1
  • 5
  • 18

4 Answers4

2

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.

BXIA
  • 61
  • 6
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
0

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

Docker for Windows USB Support

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ian Smith
  • 879
  • 1
  • 12
  • 23
0

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.