zigbee2mqtt: use extra_hosts host-gateway instead of network_mode: host

docker-compose v1 cannot clear the ports list from the base compose with
ports: [] in an override, so network_mode: host caused InvalidArgument.

Use extra_hosts with host-gateway instead: maps 'mosquitto' hostname to the
Docker bridge gateway IP so mqtt://mosquitto:1883 reaches the host-networked
mosquitto process from within the bridge-networked z2m container.
Requires Docker 20.10+ (present on chelsty-infra).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Oskar Kapala 2026-05-27 15:12:33 +02:00
parent 61e07f4318
commit b3912fe0ce

View file

@ -1,11 +1,11 @@
services: services:
zigbee2mqtt: zigbee2mqtt:
# host network: mosquitto runs with network_mode: host on chelsty-infra, # mosquitto runs with network_mode: host on chelsty-infra.
# so zigbee2mqtt must also use host networking to reach localhost:1883. # extra_hosts maps the 'mosquitto' hostname to the host gateway IP so that
network_mode: host # mqtt://mosquitto:1883 in configuration.yaml reaches the host-networked
# Clear the ports list from the base compose — host networking makes port # mosquitto process. Works with docker-compose v1 (docker 20.10+).
# mappings meaningless and docker-compose v1 errors if both are present. extra_hosts:
ports: [] - "mosquitto:host-gateway"
volumes: volumes:
# configuration.yaml lives in the runtime config dir (not in Git). # configuration.yaml lives in the runtime config dir (not in Git).
# On chelsty-infra: /opt/homelab/config/zigbee2mqtt/configuration.yaml # On chelsty-infra: /opt/homelab/config/zigbee2mqtt/configuration.yaml