Docker-Compose, Devices, and Me

So this isn’t exactly a standard issue but I figured I’d post here and see if anyone has thoughts.

Background:
After my 3rd dead SD card I’ve been starting to lay the groundwork for migrating from the Pi to a VM using Docker (not Hass.io). I’ve made some decent progress overall (excluding LetsEncrypt, that shit is a pain) but have hit a stopping point with Z-Wave. My host system doesn’t pass through USB all that well so I’ve decided to give USB over IP a shot using ser2net and socat, leaving the Z-stick in my Pi for now. (Guide here is for openhab, but a lot of the steps translate well. https://community.openhab.org/t/share-z-wave-dongle-over-ip-usb-over-ip-using-ser2net-socat-guide/34895/14 )

I’ve actually made some decent progress. On the Pi I have ser2net running and serving up ttyACM0 over port 3333. On the VM itself I have socat running and connecting just fine. Here is the socat.log:

2018/03/23 11:01:14 socat[63841] I setting option "group" to 1001
2018/03/23 11:01:14 socat[63841] I setting option "perm" to 511
2018/03/23 11:01:14 socat[63841] I openpty({6}, {7}, {"/dev/pts/1"},,) -> 0
2018/03/23 11:01:14 socat[63841] N PTY is /dev/pts/1
2018/03/23 11:01:14 socat[63841] N opening connection to AF=2 192.168.1.5:3333
2018/03/23 11:01:14 socat[63841] I starting connect loop
2018/03/23 11:01:14 socat[63841] I socket(2, 1, 6) -> 8
2018/03/23 11:01:14 socat[63841] N successfully connected from local address AF=2 192.168.1.18:50776
2018/03/23 11:01:14 socat[63841] I resolved and opened all sock addresses
2018/03/23 11:01:14 socat[63841] N starting data transfer loop with FDs [6,6] and [8,8]

And ls /dev/tty* output:

tino@ubuntu:~$ ls /dev/tty*
/dev/tty    /dev/tty17  /dev/tty26  /dev/tty35  /dev/tty44  /dev/tty53  /dev/tty62      /dev/ttyS12  /dev/ttyS21  /dev/ttyS30
/dev/tty0   /dev/tty18  /dev/tty27  /dev/tty36  /dev/tty45  /dev/tty54  /dev/tty63      /dev/ttyS13  /dev/ttyS22  /dev/ttyS31
/dev/tty1   /dev/tty19  /dev/tty28  /dev/tty37  /dev/tty46  /dev/tty55  /dev/tty7       /dev/ttyS14  /dev/ttyS23  /dev/ttyS4
/dev/tty10  /dev/tty2   /dev/tty29  /dev/tty38  /dev/tty47  /dev/tty56  /dev/tty8       /dev/ttyS15  /dev/ttyS24  /dev/ttyS5
/dev/tty11  /dev/tty20  /dev/tty3   /dev/tty39  /dev/tty48  /dev/tty57  /dev/tty9       /dev/ttyS16  /dev/ttyS25  /dev/ttyS6
/dev/tty12  /dev/tty21  /dev/tty30  /dev/tty4   /dev/tty49  /dev/tty58  /dev/ttyprintk  /dev/ttyS17  /dev/ttyS26  /dev/ttyS7
/dev/tty13  /dev/tty22  /dev/tty31  /dev/tty40  /dev/tty5   /dev/tty59  /dev/ttyS0      /dev/ttyS18  /dev/ttyS27  /dev/ttyS8
/dev/tty14  /dev/tty23  /dev/tty32  /dev/tty41  /dev/tty50  /dev/tty6   /dev/ttyS1      /dev/ttyS19  /dev/ttyS28  /dev/ttyS9
/dev/tty15  /dev/tty24  /dev/tty33  /dev/tty42  /dev/tty51  /dev/tty60  /dev/ttyS10     /dev/ttyS2   /dev/ttyS29  /dev/ttyUSB0
/dev/tty16  /dev/tty25  /dev/tty34  /dev/tty43  /dev/tty52  /dev/tty61  /dev/ttyS11     /dev/ttyS20  /dev/ttyS3
tino@ubuntu:~$

What the copy-paste doesn’t show is that it creates /dev/ttyUSB0 as a symbolic link pointing to /dev/pts/1 .

Here is the relevant portion of my docker-compose file:

homeassistant:
    container_name: home-assistant
    restart: unless-stopped
    image: homeassistant/home-assistant
    depends_on:
      - "influxdb"
    volumes:
      - /srv/docker/hass-config:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyUSB0:/dev/ttyUSB0
    network_mode: host
    privileged: true

However, once everything is up and running I go into the home-assistant container and run ls /dev/tty* I don’t get any USB devices listed.

So, folks that are smarter/more experienced than me with this, am I doing something obviously wrong?

docker does’nt follow symbolic links (at least for volumes), or actually it tries but cant find the target from the inside of the container point of view.

try using the target (/dev/pts/1) instead.

added bonus : I have a similar plan but didn’t find time for now but plan to install socat inside the container itself as it might be simpler to manage :slight_smile:

but plan to install socat inside the container itself as it might be simpler to manage

I’m very much a Docker newb so I probably did it wrong, but I originally tried installing socat in the container, but the next time I restarted everything it wasn’t there anymore. I assumed it was because the container itself is destroyed and recreated at restart? But maybe I’m wrong?

I’ll give /dev/pts/1 a shot and see if that works.

Containers are not design to last, images are.

You need to put socat & config inside the image for it to be persistent :slight_smile:

OK, that kind of makes sense to me. I think. However, if I change the image to include socat on my system and then Home-Assistant publishes a new image, wouldn’t it end up overwriting it? I guess I’d have to make sure it doesn’t auto update?

Additionally, changing the source path to /dev/pts/1 had no effect so back to the drawing board.

Every time HA publish a new image, you would have to create an image from it, which includes your additions. Its only a one line command, once you have the Dockerfile sorted, so its not a big deal.

But alternatively, I did read earlier today that someone was using a node-red z-wave<->mqtt converter, which might be of more use. Now if only I can find that thread.

Edit:
Here it is

Hmm that is interesting. I’ll have to look at that idea as well.

But the dockerfile thing has me thinking of something else, somewhat off topic.

To use the USPS component I need to install the Chrome stuff within the image/container. Should I be able to do that using a combination of a dockerfile and docker-compose? I feel like the answer is yes, but not sure if I’m reading it all correctly.

It should all be in the Dockerfile to build the image. docker-compose will enable you to start the image(s) with the same parameters.

I ran into this issue, and the problem was the “privileged: true”. After removing that line, home-assistant was able to access my USB Z-Wave stick as expected.

Hopefully this will be useful if anyone else runs into the issue.