This is a general discussion/feature request, but since it is specific to Docker Desktop for Windows, i’m opening it here. Feel free to move it somewhere more appropriate
I have recently had reason to pass a non-storage usb device to a linux docker container on windows.
Looking around for ways to achieve this, the official docker documentation flat out states wsl2 does not support this.
This, however, is untrue. Microsoft has released official guidance on using USP/IP to expose usb devices to WSL2 distros in late 2021 (Documentation, Blog post)
I have tried this myself, and successfully passed a usb device to a docker container running inside an ubuntu WSL2 distro. Specifically, i passed a Nabucasa SkyConnect stick to a HomeAssistant container on Ubuntu 20.04 LTS.
It is my understanding that the docker-distro Docker Desktop uses to run containers essentially runs and exposes a docker daemon and is in effect just “remote controlled” by the docker components installed in windows.
Assuming that is about correct, is there any (technical) barrier to including the needed packages in the docker-distro to achieve the same thing? This looks like a fairly simple way to achieve a lot of functionality.
Needing to use an external tool (usbipd) would be somewhat clunky from a user experience point of view, but i doubt anyone needing this functionality would complain about that too loudly.
I have seen user stories of trying to containerise applications that require physical usb keys as a means of licensing (i thought that died out in the 90’s…). Other use cases are running radio devices with linux software or micro controller programming.
Welcome to the forum and thank you for sharing your request! We can talk about it here, but if you realyl want this feature implemented eventually, I would recommend you to post it also in the roadmap:
Docker Desktop is based on LinuxKit,
which is based on Alpine. If the feature cannot be implemented, tit is possible that Alpine or LinuxKit makes it difficult, but I don’t know the answer.
Can you quote that statement with a link to the documentation?
the USB/IP client used in the linked documentation is available for Alpine,
so i don’t see that blocking this. If anything, i would expect an incompatibility or security implications
preventing this from becoming a feature, but we’ll see. I will definitely take your advice and post this on the roadmap!
Regarding the docs, i found the original quote, it’s actually on the general FAQ and states the following:
Can I pass through a USB device to a container?
Unfortunately, it is not possible to pass through a USB device (or a serial port) to a container as it requires support at the hypervisor level.
That is obviously wrong for linux containers on linux hosts. The FAQ does generally seem quite outdated, with the Windows FAQ stating Docker Desktop were not supported on Windows Server.
Is it actually supported on Windows Server? I haven’t seen any official statement about it yet. I know that Windows Server 2022 supports WSL, so Hyper-V was supported before and Docker Desktop wasn’t. I also know that people try to install it on Windows server and some succeeds but I still can’t find an official statement regarding Windows server. It’s like running Linux containers on a non-supported distribution which is based on a supported distribution.
Thanks for the link.
Docker tries to give you the same experience on all platforms (I know, it is not exactly the same) so that statement could be because they should support it on every platform. Or… as you assume, the FAQ could be outdated so it is definitely a good idea to take this request to the roadmap.
I’m trying to do exactly that. I want to run Home Assistant as a container on my windows machine and share the SkyConnect USB Stick with it.
What I have done so far is on my windows machine i have installed usbipd-win 4.2.0, shared and attatched the device. It shows me this in the console:
usbipd: info: Using WSL distribution 'docker-desktop' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address x.x.x.x to reach the host.
If can even see the usb device in my home assistant container by running lsusb:
lsusb
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 005: ID 10c4:ea60
Bus 002 Device 001: ID 1d6b:0003
It must be this one: Bus 001 Device 005: ID 10c4:ea60 since that is the on appearing and disappearing when i unplug it and plug it in again.
But home assistant still doesn’t recognize it. Am I missing some step?
i’m sorry, it’s been over a year, so i don’t remember much of what i did. But from re-reading my original post,
i think you already got a lot further than I did. I just ran a docker container inside one of my WSL distro’s, after installing the necessary packages there. The fact that you got a container running on Dockers WSL distro to even see the device is very interesting, I would have thought that required installing the needed packages into the docker distro.
As to your problem, I’m afraid i won’t be of much help. My experience with device management under Linux is basically zilch, but you might try and ask on the HA forums how exactly HA recognizes these sticks, and go from there. Maybe someone over there even has a bright idea for you
I didn’t manage to get it working and finally just attatched the sky connect to a raspberry pi. There i was able to use the privileged argument and got access to the usb devices. I think best practice would be to share the device instead of using the privileged argument.