Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempting to access a USB device from Docker in Windows

I've not been able to locate any instructions on how to access a USB device from Docker in Windows, exactly, although the instructions here, despite being from Mac OS X, come pretty close.

So I'm trying this on Windows, and here's what I've done so far:

  1. Upgraded Oracle VirtualBox to 5.0.16, and installed the Oracle VM VirtualBox Extensions Pack, which allows the boot2docker VM the ability to use USB 2.0 to access my device.
  2. Powered off the default virtual machine, and went to Machine → Settings… → USB. Added new USB filter, by selecting the machine from the pop-up list.
  3. Restarted the Docker Quickstart Terminal.

The thing is, I suspect that the command for running the virtual machine instance is something as follows:

docker run --privileged -v <USB directory in host machine>:<USB directory in Docker container> ...

The problem is, while in Mac OS X it appears to be /dev/bus/usb, where does it appear in Windows? Isn't it the same place? The /dev/ directory doesn't appear to have /dev/usb/.

Have I missed a step? Is the USB device path in a different place for Windows?

By the way, this is the version of Docker that I'm using when I type docker -v:

Docker version 1.10.0, build 590d5108

I'm also currently using Windows 7.

like image 346
tariqk Avatar asked Mar 17 '16 02:03

tariqk


2 Answers

I was able to get this working on a Windows host with Docker Toolbox which I'm assuming the OP is using.

Stop the boot2docker vm:

host:~$ docker-machine stop default

Open VirtualBox manager and add USB filters as required.

Start the boot2docker vm:

host:~$ docker-machine start default

Since the USB devices are connected to the boot2docker VM, the commands need to be run from that machine. Open up a terminal with the VM and run the Docker run command:

host:~$ docker-machine ssh
docker@default:~$ docker run -it --privileged ubuntu bash

If you want the Docker container to work with USB devices plugged in after the container is started you can use:

docker@default:~$ docker run -it --privileged -v /dev:/dev ubuntu bash

Most other examples I see are using -v /dev/bus/usb:/dev/bus/usb which will only work for certain USB devices. I had to use /dev for an application that created /dev/sg2 when the USB port was plugged in.

Note, the flags -it are only required as an example here so that you can get a Bash terminal inside an Ubuntu container. They are not actually required for this to work.

like image 140
rrpilot Avatar answered Sep 19 '22 14:09

rrpilot


Looks like biting the bullet, despite not seeing /dev/bus/usb and typing the following command works:

docker run -it --privileged -v /dev/bus/usb:/dev/bus/usb ...

(in my case, it was docker run-it --privileged -v /dev/bus/usb:/dev/bus/usb -v (shared directory path):(path in container) debian:latest bash, but your command will be different depending on what you're doing).

Also, if you're working on Android devices and you want to still access them when they're on the bootloader, you will need to create two filters within VirtualBox: one for when you're using ADB, the other when you're using fastboot.

like image 24
tariqk Avatar answered Sep 21 '22 14:09

tariqk