How Do I Pass Through A USB Device To A Docker Container?


Recommended Posts

hi all,

 

So i have RF link running on a arduino mega 2560 and tested it on a windows pc in domoticz and it's working great.

 

Having trouble getting it connected to my docker container in unraid.

 

 

dmesg | tail

[ 1298.319801] usb 1-1.1: USB disconnect, device number 3
[ 1303.099442] usb 1-1.1: new full-speed USB device number 5 using ehci-pci
lsusb                                                         

Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

i have tried

--device=/dev/bus/usb/001/005:/dev/ttyS0 

--device=/dev/bus/usb/001/005

 

but cant see it shown as a usb device or a serial port in the container - 

 

docker exec -it domoticz dmesg | grep tty
console [tty0] enabled
docker exec -it domoticz lsusb
Bus 005 Device 001: ID 1d6b:0003
Bus 003 Device 001: ID 1d6b:0001
Bus 002 Device 002: ID 8087:0024
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 004: ID 0781:5581
Bus 001 Device 005: ID 1a86:7523
Bus 001 Device 002: ID 8087:0024
Bus 002 Device 003: ID 0424:2660
Bus 004 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 005 Device 002: ID 0411:0240

any ideas?

 

thanks

Edited by gareth_iowc
Link to comment
5 minutes ago, gareth_iowc said:

hi all,

 

So i have RF link running on a adruino mega and tested it on a windows pc in domoticz and it's working great.

 

Having trouble getting it connected to my docker container in unraid.

 

 


dmesg | tail

[ 1298.319801] usb 1-1.1: USB disconnect, device number 3
[ 1303.099442] usb 1-1.1: new full-speed USB device number 5 using ehci-pci

lsusb                                                         

Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

i have tried

--device=/dev/bus/usb/001/005:/dev/ttyS0 

--device=/dev/bus/usb/001/005

 

but cant see it shown as a usb device or a serial port in the container - 

 


docker exec -it domoticz dmesg | grep tty
console [tty0] enabled

docker exec -it domoticz lsusb
Bus 005 Device 001: ID 1d6b:0003
Bus 003 Device 001: ID 1d6b:0001
Bus 002 Device 002: ID 8087:0024
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 004: ID 0781:5581
Bus 001 Device 005: ID 1a86:7523
Bus 001 Device 002: ID 8087:0024
Bus 002 Device 003: ID 0424:2660
Bus 004 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0002
Bus 005 Device 002: ID 0411:0240

any ideas?

 

thanks

 

I guess you open it as a device in domoticz normally? If you don't get a device when connecting the usb, you might need a driver for it to load the device node.

Since this is a usb to serial device, it's going to be ttyUSB0.

 

Does it work if you load the correct module?

 

modprobe ch341

 

Edited by saarg
Link to comment
25 minutes ago, saarg said:

 

I guess you open it as a device in domoticz normally? If you don't get a device when connecting the usb, you might need a driver for it to load the device node.

Since this is a usb to serial device, it's going to be ttyUSB0.

 

Does it work if you load the correct module?

 


modprobe ch341

 

 

ah ok so i changed my config to - --device=/dev/bus/usb/001/005:/dev/ttyUSB0

 

After making that change i can now see an option in the port selection menu - "dev/ttyUSB0"

 

Is there anyway to check comms as i'm not sure it's working.

 

i have tried to add a temperature sensors like i did on windows and nothing is coming up.

 

sorry how is the modprobe ch341 command executed? 

Screen Shot 2018-01-28 at 23.12.51.png

Link to comment
  • 2 weeks later...
  • 1 month later...

I am trying to use a Aeon Labs Aeotec Z-Wave Z-Stick, Gen5 but can't seem to get my devices hooked up.  I put this in the privileged line

 

 --device=/dev/ttyACM0

But it doesn't seem to be working here is some lines in my log file

�[39m�[31m2018-03-18 14:52:29.936 Error, ERROR: Failed to open serial port /dev/ttyACM0
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[32m2018-03-18 14:52:29.936 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[32m2018-03-18 14:52:29.936 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[31m2018-03-18 14:52:34.936 Error, ERROR: Cannot open serial port /dev/ttyACM0. Error code 13
�[39m�[32m2018-03-18 14:52:34.936 Always,
�[39m�[32m2018-03-18 14:52:34.936 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:34.936 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[31m2018-03-18 14:52:34.937 Error, ERROR: Failed to open serial port /dev/ttyACM0
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m2018-03-18 14:52:34.937 �[1;31mError: OpenZWave: Driver Failed!!�[0;0m
2018-03-18 14:54:29.969 New sensors allowed for 5 minutes...
2018-03-18 14:54:44.740 New sensors allowed for 5 minutes...
2018-03-18 14:55:58.836 New sensors allowed for 5 minutes...
2018-03-18 14:56:16.068 New sensors allowed for 5 minutes...
2018-03-18 14:56:16.068 OpenZWave: Node Include command initiated...

What am I doing wrong?

Link to comment
54 minutes ago, mgranger said:

I am trying to use a Aeon Labs Aeotec Z-Wave Z-Stick, Gen5 but can't seem to get my devices hooked up.  I put this in the privileged line

 


 --device=/dev/ttyACM0

But it doesn't seem to be working here is some lines in my log file


�[39m�[31m2018-03-18 14:52:29.936 Error, ERROR: Failed to open serial port /dev/ttyACM0
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[32m2018-03-18 14:52:29.936 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[32m2018-03-18 14:52:29.936 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:29.936 Always,
�[39m�[31m2018-03-18 14:52:34.936 Error, ERROR: Cannot open serial port /dev/ttyACM0. Error code 13
�[39m�[32m2018-03-18 14:52:34.936 Always,
�[39m�[32m2018-03-18 14:52:34.936 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:34.936 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[31m2018-03-18 14:52:34.937 Error, ERROR: Failed to open serial port /dev/ttyACM0
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, Dumping queued log messages
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m�[32m2018-03-18 14:52:34.937 Always, End of queued log message dump
�[39m�[32m2018-03-18 14:52:34.937 Always,
�[39m2018-03-18 14:52:34.937 �[1;31mError: OpenZWave: Driver Failed!!�[0;0m
2018-03-18 14:54:29.969 New sensors allowed for 5 minutes...
2018-03-18 14:54:44.740 New sensors allowed for 5 minutes...
2018-03-18 14:55:58.836 New sensors allowed for 5 minutes...
2018-03-18 14:56:16.068 New sensors allowed for 5 minutes...
2018-03-18 14:56:16.068 OpenZWave: Node Include command initiated...

What am I doing wrong?

 

I bet you are on unraid 6.5. Then you need to add the below in your go file to change permissions of /dev/ttyACM0 so it's possible to open by domoticz.

 

chmod 777 /dev/ttyACM0

 

This is a bug in docker CE and will be fixed in 18.03. Then we just have to hope @limetech adds it to a release in the near future.

 

Here is the issue if anyone is interested. https://github.com/docker/docker-ce/pull/450

  • Like 1
Link to comment
On 18.3.2018 at 8:59 PM, saarg said:

 

I bet you are on unraid 6.5. Then you need to add the below in your go file to change permissions of /dev/ttyACM0 so it's possible to open by domoticz.

 


chmod 777 /dev/ttyACM0

 

This is a bug in docker CE and will be fixed in 18.03. Then we just have to hope @limetech adds it to a release in the near future.

 

Here is the issue if anyone is interested. https://github.com/docker/docker-ce/pull/450

 

I have a 3D Printer connected as /dev/ttyACM0, and it isn't always turned on, it constantly connects and disconnects. Therefore adding 

chmod 777 /dev/ttyACM0

isn't doing the job for me.

Is there any workaround which makes

chmod 777 /dev/ttyACM0

 persistent trough reconnects and not only trough reboots?

Edited by Diggewuff
Link to comment
  • 4 weeks later...
On 9/10/2016 at 8:22 AM, saarg said:

If the container doesnt start, you don't have the device.

You might have to use VM in stead and pass the USB device through.

I'm looking to do the same. Trying to pass the stick to a Docker through unRAID seems very tricky and annoying to keep that way. Are you saying you can avoid this headache my installing a Linux VM instead, passing the stick to the VM (which works reliably?), then installing HASS on VM and then Docker can easily see that device because it is already in the system it is in? The HASS install on Linux, could it be via Docker or would it have to be installed without Docker?

Link to comment
  • 1 year later...
On ‎2‎/‎25‎/‎2017 at 12:15 AM, poldim said:

Just sharing what I've done:

 

  1. Inserted my Z Wave stick into my UNRAID server.
  2. Went to the main UNRAID log and found this:
    
    Feb 24 08:52:12 ChiRAID kernel: usb 5-1: new full-speed USB device number 4 using uhci_hcd
    Feb 24 08:52:12 ChiRAID kernel: cdc_acm 5-1:1.0: ttyACM0: USB ACM device
    Feb 24 08:52:12 ChiRAID kernel: usbcore: registered new interface driver cdc_acm
    Feb 24 08:52:12 ChiRAID kernel: cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

     

  3.  Found that the system is referring to the stick as ttyACM0 per above.
  4.  Went into Home assistant docker settings, enabled advanced view, and made the following changes:
    
    Extra Parameters:	--device=/dev/ttyACM0
    Privileged:			ON
     
  5.  Followed instructions on setting up z-wave stick by adding the required code to the yaml file:
    
    zwave:
      usb_path: /dev/ttyACM0

     

 

Brand new to Unraid and been scratching my head for a couple of hours trying to make a USB 433Mhz Transceiver work with Domoticz... until I found your post :)

 

Works great thanks to you... I did however leave Privileged Off.

 

Many Thanks

Link to comment
  • 1 year later...
  • 5 months later...

I've changed my USB stick to a ZZH and it's using ttyUSB0. Problem is, my docker cannot access it.

 

I believe its something to do with permissions:

 

# ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jun 24 20:32 /dev/ttyUSB0

 

I'm not sure what to do to allow the docker (zigbee2mqtt) to access the device.  

My docker extra params has --device=/ttyUSB0

 

Earlier in this thread, its mentioned that:

"For these devices all needed is to add the user running the software in the container to the dialout group."

 

But I don't know how to do that.

 

Link to comment
  • 6 months later...
On 6/23/2021 at 5:53 PM, jj_uk said:

So if I add this to the go file, will that work at restart?


 

echo "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"0451\", ATTRS{idProduct}==\"16a8\", ATTRS{serial}==\"serial num removed\", SYMLINK+=\"zigbee2mqtt\"" > /etc/udev/rules.d/99-usb-serial.rules

 

This is how I keep mine persistent:

 

Part 1:

# lsusb for vendor:product idProduct


# udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1

where USB0 is the device you are looking for


# OR; udevadm info -a -n /dev/bus/usb/000/000 | grep '{serial}' | head -n1

if you can't find the USB device, search if it's in the BUS


# nano /etc/udev/rules.d/99-usb-rules.rules

make your own rules folder

 

Part 2:

# cp /etc/udev/rules.d/99-usb-rules.rules /boot/config/rules.d/99-usb-rules.rules

copy your rules to the boot config
# nano /boot/config/go
# add and save --> cp /boot/config/rules.d/99-serial-rules.rules /etc/udev/rules.d/99-serial-rules.rules
# chmod 644 /etc/udev/rules.d/99-serial-rules.rules

Link to comment
  • 1 year later...

the best method to passthrough usb to docker is via device by-id

open unraid terminal
type 

ls -l /dev/serial/by-id

 

you will get output of your devices with names

 

image.thumb.png.1ad7d1662cb968df44597ff76a0b040c.png

 

copy the whole BLUE name of your device

 

go to your docker and edit config

 

add /dev/serial/by-id/  before pasting the name from above.

eg

/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_dcf756dbb712ec118bca20c7bd930c07-if00-port0

then add :/dev/zigbee to the end -  this is the container mount point

 

so you end up with this in your Docker Host config:

/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_dcf756dbb712ec118bca20c7bd930c07-if00-port0:/dev/zigbee

 

if anywere inside your docker program it asks for the device location you would set it to :
/dev/zigbee

 

image.png.9be0ab12f9a482abdcdb5a04c7d09f78.png

 

 

Edited by TRusselo
  • Like 1
  • Thanks 2
Link to comment
On 2/2/2023 at 12:53 PM, TRusselo said:

the best method to passthrough usb to docker is via device by-id

open unraid terminal
type 

ls -l /dev/serial/by-id

 

you will get output of your devices with names

 

image.thumb.png.1ad7d1662cb968df44597ff76a0b040c.png

 

copy the whole BLUE name of your device

 

go to your docker and edit config

 

add /dev/serial/by-id/  before pasting the name from above.

eg

/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_dcf756dbb712ec118bca20c7bd930c07-if00-port0
image.png.9be0ab12f9a482abdcdb5a04c7d09f78.png

 

 

 

I have the exact same device as your screenshot and am passing it through the exact same way (by the /dev/serial/by-id path) and it's still not registering in my docker app (Home Assistant). Any ideas why that would be? I've been pulling my hair out over this for a while.

 

At first I thought it was passing through correctly since "lsusb" output in the docker container included the device, but then I noticed that even when I wasn't passing it through explicitly in the unraid UI, lsusb still listed the zigbee dongle. 

 

Link to comment
  • 2 weeks later...
On 2/3/2023 at 3:26 PM, GameKing505 said:

 

I have the exact same device as your screenshot and am passing it through the exact same way (by the /dev/serial/by-id path) and it's still not registering in my docker app (Home Assistant). Any ideas why that would be? I've been pulling my hair out over this for a while.

 

At first I thought it was passing through correctly since "lsusb" output in the docker container included the device, but then I noticed that even when I wasn't passing it through explicitly in the unraid UI, lsusb still listed the zigbee dongle. 

 

try adding :/dev/zigbee to the end of the VALUE

 

/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_dcf756dbb712ec118bca20c7bd930c07-if00-port0:/dev/zigbee

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.