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


Recommended Posts

I originally posted this on a specific container support thread, but realized this is specific to the usage of docker in general, not the specific container I was using.

 

For transparency, I'm attempting to attach my Z-Wave stick to my unRAID console.  From there, I would like the container to be able to read from this Z-Wave Stick.  I imagine this would be the same process for any docker needing to see a USB device.  The one I'm using in this case is Home-Assistant.

 

For starters, I have located the proper USB device on my unRAID hardware.  When I run command lsusb on my unRAID console, I get:

 

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 004: ID 0781:5571 SanDisk Corp. Cruzer Fit

Bus 001 Device 007: ID 0658:0200 Sigma Designs, Inc.

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

 

The device I need to pass through is on Bus 001 and is Device 007.  This changes if I unplug and replug, but that's a problem for another day.

 

I can find the specific path of this USB device on /dev/bus/usb/001/007.  I see a a few posts mentioning /dev/ttyUSB0 or /dev/ttyS0, but I don't know what the connection is.

 

Inside the specific docker I'm looking at, without any type of mapping, if I docker exec /bin/bash into it, I can navigate to /dev/bus/usb and find the same lists of devices.  But for some reason, why I tell the docker to look at that path, it does not recognize the device.  Does this path not mean the same thing as say C:\ would I Windows?  I've also tried to specifically map /dev/bus/usb/001/007 to /dev/bus/usb/001/007 and also mapped to /dev/ttyUSB0, but nothing changes.

 

Is there a certain variable, path, port or device I need to specifically map on the docker container parameters beyond what I've done?  Is there something completely different that I'm missing?

 

Thanks for any insight to this issue!

Link to comment

How did you map the device?

If you look in the oscam thread in my signature, it tells you how to pass through a device to a container.

You could try the below, but notice that it most likely changes on reboot.

 

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

 

You have to check in the syslog to know if the device gets assigned to ttyUSB0 or something similar. If it does, you could use the below tag.

 

--device=/dev/ttyUSB0

Link to comment

How did you map the device?

If you look in the oscam thread in my signature, it tells you how to pass through a device to a container.

You could try the below, but notice that it most likely changes on reboot.

 

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

 

You have to check in the syslog to know if the device gets assigned to ttyUSB0 or something similar. If it does, you could use the below tag.

 

--device=/dev/ttyUSB0

 

And these tags you mention are added to the "Extra Parameter" line in the docker setup?  Should privileged be on or off?

 

Also, when you say to check in the syslog to know if it's being assigned to ttyUSB0, do I ADD this tag, or CHANGE to this tag?

 

I will review the oscam thread in your signature next.

Link to comment

These are the errors I get within the docker:

 

2016-05-24 06:46:01.929 Info, mgr,    Added driver for controller /dev/bus/usb/001/009

2016-05-24 06:46:01.929 Info,  Opening controller /dev/bus/usb/001/009

2016-05-24 06:46:01.929 Info, Trying to open serial port /dev/bus/usb/001/009 (attempt 1)

2016-05-24 06:46:01.929 Error, ERROR: Failed to set serial port parameters

2016-05-24 06:46:01.929 Error, ERROR: Failed to open serial port /dev/bus/usb/001/009

2016-05-24 06:46:01.929 Warning, WARNING: Failed to init the controller (attempt 0)

 

EDIT:  I went through the post, but it basically says what your response did.  Still unsure howto connect this thing!

Link to comment

On the docker, there is something called /dev/ttyS0.  There is no ttyUSB0.  If I add the extra parameter instead of

 

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

 

It says serial port opened, but I still get errors.

 

2016-05-24 07:20:48.298 Info, mgr,    Added driver for controller /dev/ttyS0

2016-05-24 07:20:48.298 Info,  Opening controller /dev/ttyS0

2016-05-24 07:20:48.298 Info, Trying to open serial port /dev/ttyS0 (attempt 1)

2016-05-24 07:20:48.298 Info, Serial port /dev/ttyS0 opened (attempt 1)

2016-05-24 07:20:48.299 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_VERSION: 0x01, 0x03, 0x00, 0x15, 0xe9

2016-05-24 07:20:48.299 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_MEMORY_GET_ID: 0x01, 0x03, 0x00, 0x20, 0xdc

2016-05-24 07:20:48.299 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES: 0x01, 0x03, 0x00, 0x05, 0xf9

2016-05-24 07:20:48.299 Detail, contrlr, Queuing (Command) FUNC_ID_SERIAL_API_GET_CAPABILITIES: 0x01, 0x03, 0x00, 0x07, 0xfb

2016-05-24 07:20:48.299 Detail, contrlr, Queuing (Command) FUNC_ID_ZW_GET_SUC_NODE_ID: 0x01, 0x03, 0x00, 0x56, 0xaa

2016-05-24 07:20:48.300 Detail,

2016-05-24 07:20:48.300 Info, contrlr, Sending (Command) message (Callback ID=0x00, Expected Reply=0x15) - FUNC_ID_ZW_GET_VERSION: 0x01, 0x03, 0x00, 0x15, 0xe9

2016-05-24 07:20:49.300 Error, contrlr, ERROR: Dropping command, expected response not received after 1 attempt(s)

2016-05-24 07:20:49.300 Detail, contrlr, Removing current message

2016-05-24 07:20:49.300 Detail, contrlr, Notification: Notification - TimeOut

Link to comment

The tag goes in the extra parameter box.

You either add one or the other tag, not both.

Unplug your device add it and check your syslog to see if the device gets assigned to ttyUSBx. If not, use the first tag I provided.

 

It might be that you have to change permissions on the device inside the container. Does the device need drivers?

Link to comment

The tag goes in the extra parameter box.

You either add one or the other tag, not both.

Unplug your device add it and check your syslog to see if the device gets assigned to ttyUSBx. If not, use the first tag I provided.

 

It might be that you have to change permissions on the device inside the container. Does the device need drivers?

 

It's the Aeon Labs Aeotec Z-Wave Z-Stick, Gen5.  I do not believe it needs drivers.

 

When I unplug and replug in the device, am I checking the syslog of my unraid system, or of my container?

 

When I check unraid, I get this:

 

May 24 09:14:49 Tower kernel: usb 1-1.3: USB disconnect, device number 9

May 24 09:14:57 Tower kernel: usb 1-1.3: new full-speed USB device number 10 using ehci-pci

May 24 09:14:57 Tower kernel: cdc_acm 1-1.3:1.0: ttyACM0: USB ACM device

Link to comment

Thanks a lot for this! I will be doing it in a few days, also building an unRaid disk and Home Assistant

 

Is it possible to map the USB device with a udev rule so it's always mapped to /dev/ttyACM0?

I don't know how udev works, but I suspect the udev rule have to be made before the go script executes for this to work?

If so, you will have to unpack bzroot, add the udev rule and then pack it again. You could look at CHBMB build script for the media build for how to do it.

Link to comment
  • 3 months later...

Hello, sorry old thread. But I have the same problem, but with a Tellstick USB device. Also using Home-Assistant.

Problem is I only see this in the syslog when I plug in the device:

 

Sep 6 22:20:57 unTRUE kernel: usb 2-1.7: USB disconnect, device number 4

Sep 6 22:21:10 unTRUE kernel: usb 2-1.7: new full-speed USB device number 5 using ehci-pci

 

Can't see if it's TTY or USB0?

 

Also having these errors in the Home-Assistant Log:

16-09-06 22:26:51 homeassistant.config: Found deprecated temperature unit in core config, expected unit system. Replace 'temperature_unit: °C' with 'unit_system: metric'
16-09-06 22:26:52 homeassistant.config: Incomplete core config. Auto detected elevation: 177
16-09-06 22:26:52 homeassistant.components.sensor.tellstick: Could not initialize Tellstick.
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/sensor/tellstick.py", line 50, in setup_platform
    core = telldus.TelldusCore()
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory
16-09-06 22:26:52 homeassistant.bootstrap: Error during setup of component tellstick
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/bootstrap.py", line 157, in _setup_component
    result = component.setup(hass, config)
  File "/usr/src/app/homeassistant/components/tellstick.py", line 68, in setup
    core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher())
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory

 

I don't really know where to go from here..

Thanks in advance

Link to comment

Hello, sorry old thread. But I have the same problem, but with a Tellstick USB device. Also using Home-Assistant.

Problem is I only see this in the syslog when I plug in the device:

 

Sep 6 22:20:57 unTRUE kernel: usb 2-1.7: USB disconnect, device number 4

Sep 6 22:21:10 unTRUE kernel: usb 2-1.7: new full-speed USB device number 5 using ehci-pci

 

Can't see if it's TTY or USB0?

 

Also having these errors in the Home-Assistant Log:

16-09-06 22:26:51 homeassistant.config: Found deprecated temperature unit in core config, expected unit system. Replace 'temperature_unit: °C' with 'unit_system: metric'
16-09-06 22:26:52 homeassistant.config: Incomplete core config. Auto detected elevation: 177
16-09-06 22:26:52 homeassistant.components.sensor.tellstick: Could not initialize Tellstick.
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/sensor/tellstick.py", line 50, in setup_platform
    core = telldus.TelldusCore()
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory
16-09-06 22:26:52 homeassistant.bootstrap: Error during setup of component tellstick
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/bootstrap.py", line 157, in _setup_component
    result = component.setup(hass, config)
  File "/usr/src/app/homeassistant/components/tellstick.py", line 68, in setup
    core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher())
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory

 

I don't really know where to go from here..

Thanks in advance

 

It doesn't create anything in /dev/ so try to find the Bus and device number either with lsusb command or look in unraids webgui under Tools --> devices.

Use the below tag in the Extra parameters field in the container and change the last two number to what your Bus and device number is.

First number is Bus, second device.

 

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

 

Don't know if it will work, but worth a try.

Link to comment

It doesn't create anything in /dev/ so try to find the Bus and device number either with lsusb command or look in unraids webgui under Tools --> devices.

Use the below tag in the Extra parameters field in the container and change the last two number to what your Bus and device number is.

First number is Bus, second device.

 

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

 

Don't know if it will work, but worth a try.

 

Found the following in in the devices:

 

Bus 002 Device 004: ID 1781:0c31 Multiple Vendors Telldus TellStick Duo

 

I tried adding the following in the extra parameters:

 

--device=/dev/bus/usb/002/004

 

And then I got the following error in Home-Assistant. :/

 

16-09-08 17:39:30 homeassistant.config: Found deprecated temperature unit in core config, expected unit system. Replace 'temperature_unit: °C' with 'unit_system: metric'
16-09-08 17:39:30 homeassistant.config: Incomplete core config. Auto detected elevation: 177
16-09-08 17:39:31 homeassistant.components.sensor.tellstick: Could not initialize Tellstick.
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/sensor/tellstick.py", line 50, in setup_platform
    core = telldus.TelldusCore()
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory
16-09-08 17:39:31 homeassistant.bootstrap: Error during setup of component tellstick
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/bootstrap.py", line 157, in _setup_component
    result = component.setup(hass, config)
  File "/usr/src/app/homeassistant/components/tellstick.py", line 68, in setup
    core = telldus.TelldusCore(callback_dispatcher=DirectCallbackDispatcher())
  File "/usr/local/lib/python3.4/site-packages/tellcore/telldus.py", line 107, in __init__
    self.lib = Library(library_path, callback_dispatcher)
  File "/usr/local/lib/python3.4/site-packages/tellcore/library.py", line 312, in __init__
    lib = DllLoader.LoadLibrary(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 429, in LoadLibrary
    return self._dlltype(name)
  File "/usr/local/lib/python3.4/ctypes/__init__.py", line 351, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libtelldus-core.so.2: cannot open shared object file: No such file or directory

Link to comment

No more ideas from me I'm afraid.

 

One just answered in the gitter chat! :)

https://gitter.im/home-assistant/home-assistant

 

@thetruetype think you need to add this

```

--privileged -v /dev/ttyACM0:/dev/ttyACM0

--privileged -v /dev/ttyACM0:/dev/ttyACM0

 

full docker command to start and pass the physical device to the virtual env is:

 

docker run -d --name="MNHA" -v /ha:/config -v /etc/localtime:/etc/localtime:ro --privileged -v /dev/ttyACM0:/dev/ttyACM0 --net=host homeassistant/home-assistant

 

 

vnv0ccbf.png

Link to comment

Do you have /dev/ttyACM0? Have you tried to pass it through with the below added in the Extra parameters box?

 

--device=/dev/ttyACM0

 

Running the container with the --privileged option, there is no need to specify the device mount as the container already gets access to all devices.

Link to comment

Do you have /dev/ttyACM0? Have you tried to pass it through with the below added in the Extra parameters box?

 

--device=/dev/ttyACM0

 

Running the container with the --privileged option, there is no need to specify the device mount as the container already gets access to all devices.

 

I tried to do like he posted with --privileged, but it didn't work correctly :/

 

With

--device=/dev/ttyACM0

it didn't even start. :/

Link to comment

Do you have /dev/ttyACM0? Have you tried to pass it through with the below added in the Extra parameters box?

 

--device=/dev/ttyACM0

 

Running the container with the --privileged option, there is no need to specify the device mount as the container already gets access to all devices.

 

I tried to do like he posted with --privileged, but it didn't work correctly :/

 

With

--device=/dev/ttyACM0

it didn't even start. :/

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.

Link to comment

I think a workaround is to the use the Unassigned Devices plugin: http://lime-technology.com/forum/index.php?topic=45807.0

A plugin you should already have installed on your server. ;)

 

Mount the USB and set it to auto-mount.

And then in the docker container setup add a container path and set it to /mnt/disks/"Name of USB device" and then the path you want used in the container.

 

This is not about a USB hard drive in a container, but a non storage USB device.

Link to comment
  • 2 months later...

Hi,

Im also very interesting in this configuration!

 

I have tried to set up my zwave.me but without any luck so far after reading a lot on this topic (a bit confusing...).

If someone has got this working, it would be nice to get both Unraid docker setup and zwave config for the USB device!

 

Thanks!

/tompa

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.