Putting zigbee2mqtt and zwave2mqtt in Docker Swarm

NOTE: This ended up not being very stable and I’ve stopped using it.

After following some very helpful posts about using macvlan and swarm to deploy Home-assistant there I wanted to do the same for zigbee/zwave 2mqtt containers as well. Even though they only run on a single host it makes it easier to manage their updates.

Following the guide for zigbee2mqtt I wanted to make it more generic to work with zwave or whatever else and deploy to whatever nodes I needed it to.

So here we have it, as long as you’ve configured udev before hand this will let you map your devices.

I just tag my hosts with a label volume.devices=true and then set the service to have a container label, not a service label of volume.device=/dev/ttyUSB0 or whatever the real device is.

What I mean by not a service label is that it’s at the top level of the container settings instead of nested in the deploy.labels. This way the event that is captured contains the label with the device path and no further querying of docker is required in order to setup the permissions for the new container to access the device path.

And yeah, this is kinda insecure but there is no external interface and you’d be running the exact same thing with systemd or something. This just makes the setup far simpler and portable so the steps to rebuild a swarm host that needs device access is next to nothing.