Is it possible to share a USB GPS dongle with multiple Docker containers? Is it possible to share a USB GPS dongle with multiple Docker containers? docker docker

Is it possible to share a USB GPS dongle with multiple Docker containers?


[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:

$ lsusbBus 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