Passthrough USB to Docker
-
In this example I will be passing through a Sonoff Zigbee antenna to a Ubuntu 22.04 server running Docker. We will be adding the device to a Home Assistant container within Docker.
First you’ll need to plug the USB antenna into your computer (In my case I am running an Ubuntu 22.04 server). If you need to find what version you are running, you can use:
lsb_release -a- SSH into the server and run:
ls /dev/serial/by-idThis will list the USB devices plugged in, and you should see an output like this:
usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_<Device ID>-port0. The<Device ID>will be whatever it shows when you run the command above. You will need to copy this line of text, because this is what we are going to be pasting into our Docker Compose file.
In the compose file, we need to add the device like this:
devices: - /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_<Device ID>-port0Here is an example with Home Assistant:
services: homeassistant: container_name: homeassistant image: "ghcr.io/home-assistant/home-assistant:stable" ports: - "8123:8123" volumes: - homeassistant-config:/config - /etc/localtime:/etc/localtime:ro - /run/dbus:/run/dbus:ro restart: unless-stopped devices: - /dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_<Device ID>-port0 volumes: homeassistant-config:After you restart the container the device should show up in the
Devices & servicesmenu within the Home Assistant settings. I believe this will work for other USB devices and other containers, but I have only tried it with this specific example.