I have a Realtek RTL2832U dongle for software defined radio (SDR). I would like to give my Docker container access to the device.
The solutions I have found so far:
The --privileged flag for docker run. Problem: insecure
The --device flag for docker run. Problem: the Realtek dongle isn't a mounted USB device, so I can't find a device path (i.e. /dev/ttyUSB0) by running df -h. However, the device does show up when I run lsusb, as Bus 003 Device 027.
My questions:
Is it possible to mount a usb device that isn't a data storage device? If so, how would I do that?
If not, how can I give my docker container access to this usb device?
Related
I need to access the USB device from the Docker container that ran on the Windows host (WSL2). The device is a USB flash drive with the content (files) and serial number. How to mount it and access the data?
I've tried --device=/dev/bus/usb:/dev/bus/usb and usbipd but it doesn't work.
I am using a VK-172 U-Blox AG GPS in my Raspberry Pi 3 as part of a receive-only APRS iGate. I am running Docker on the RPi. Right now I am running a Docker container that uses the GPS dongle for position data with Direwolf, which is reported to the APRS-IS network.
I would also like to run a Docker container to use the GPS as a very accurate time reference for other machines on my network.
Is it possible to share a USB GPS dongle with multiple Docker containers?
73 de K6JEB
[Disclaimer]
I'm not sure if you want to know how to share any USB device with a container or in particular this USB GPS dongle (because of some additional requirements, configuration etc). But I'll try to do my best.
Add singe USB device
If you want to add a USB device (that is plugged in host) to the container. You can use --device docker run option.
--device Add a host device to the container
You will need bus and device on which your device is connected to (use lsusb or dmesg to find that). Example:
Lets say I want to add this Yubikey to contaiener:
$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
....
Bus 001 Device 017: ID 1050:0010 Yubico.com Yubikey (v1 or v2)
then I would run container like so:
docker run -dit --device /dev/bus/usb/<BUS>/<DEVICE> <image>
docker run -dit --device /dev/bus/usb/001/017 <image>
Then this USB device will be accessible inside a container. Now for your use case add this option to containers which need to have access to that device.
Please note! you may need --privileged flag in order to have correct permissions.
--privileged Give extended privileges to this container
Adding all USB devices
You can also connect all available USB devices to a contiaer or containers by mounting whole /dev/usb/bus directory:
docker run -dit --privileged -v /dev/bus/usb:/dev/bus/usb <image>
Is this what you need?
Regards
Is it possible to access a USB device (which is not a memory stick) in a Docker container?
I've come across the --—privileged and --device options which I guess would work if I had a Linux host, but they don't seem to work in macOS where USB devices don't show up in /dev.
It looks like docker-machine + VirtualBox is the way to go. I documented the steps I took in the blog post How to use a USB device in a Docker container on Mac.
I'm building a headless softphone application. I know I can build wss or web server with the given tools... but my web app needs to do some pjsip and other codec things with the host's speaker and microphone. Are these devices shared between the mac/windows/linux hosts and the docker container?
I had to use the microphone and speakers of the linux host from a docker container. Since in linux/unix based OSs devices are special files in the file system this solution should apply. In Windows it won't.
I discovered that the ubuntu image I was using in my container didn't have the ALSA drivers needed to use the soundcard. So after installing them in the docker container:
sudo apt-get install -y alsa-base alsa-utils
and running the docker image with the following parameters:
docker run --device /dev/snd:/dev/snd <container_name>
it worked. You can test if it works by invoking aplay and arecord inside the container.
Never tried with speakers and microphone, anyway you can access host devices using the option --device in docker run.
See Add host device to container (–device) in Docker run reference for more details.
I believe this was possible via VirtualBox when using Docker Toolbox, and the privileged flag on the container, but I'm not certain if Hyper-V controlled Docker host can support this. I am ultimately attempting to access a microcontroller programmer via the USB device.
Does Docker for Windows with Hyper-V support this?
Update: so far it seems like there are only expensive vendor supplied hardware solutions for this as the possible options for Hyper-V virtual hardware is limited to SCSI drives and optical media.