I'm currently trying to run a USB Scale and USB Barcode scanner on a docker container hooked up to my MacBook Pro. I see how to do it on linux, by using the --device or --privileged flag, but I can't seem to figure out where exactly these devices reside on my mac since they are not storage devices. Any ideas?
Related
So I am on a mac and I need USB forwarded into docker image. Thus I spin up docker-machine on virtualbox with usb forwarding. The only thing is that it does not see my docker images from Docker for Mac and I really would like to share them. How to do such thing?
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.
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.
I would like to run a GPU enabled app (Gazebo) inside a docker container on my MacBook Pro.
I seemed to me, through my research, that about a year ago, Docker released a native Docker app for MacOS.
Before that, Docker used to spawn an entire Linux VM and run the container on top of it.
Now, it apparently uses some native hypervisor framework, making it more optimized and closer to the hardware, changing entirely Docker's approach to containerization on a Mac.
All this is not very clear to me and I am not sure of everything I stated.
Is it now possible to use my macbook pro's GPU from a docker container, and, if yes, how ?
The command line I'm using right now, which works for regular X11 apps but not GPU-enabled apps like Gazebo is:
xhost +
docker run -it -e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix image_name bash
There's still a virtual machine involved.
Docker for Mac uses a virtualization layer called XHyve. It's a lot thinner and more lightweight than VirtualBox or such (emulates fewer peripherals), but it's still virtualization.
PCI passthrough is (theoretically) possible, but you can't pass through your laptop's main GPU and still use it.
Hardware with an IOMMU (and yes, your MacBook Pro has an Intel chipset with such support) can allow a virtualized environment direct access to PCI hardware.
However, you can't cede control of a piece of hardware to a VM and still use that hardware from the host. (Some high-end server network cards work around this by having multiple PCI endpoints, so the host and each guest gets a different endpoint to talk to).
So -- you could get an external Thunderbolt-attached GPU, and it might work... in the future.
The underlying support in Xhyve isn't there yet (as of this mid-2017 writing), and even on KVM (used by a lot of folks doing pioneering work here), there are only limited reports of success (with a specific video card -- the Radeon HD 5850).
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