Zwave-js-ui with docker-compose: works by IP address but not by container name

Hello,

I have Home Assistant installed using docker-compose, together with zwave-js-ui. I have everything working properly, but on restart, sometimes the IP address of the containers change, and HA is unable to connect to zwave. The usual way to deal with this is to use container names instead of IP addresses, but it seems Home Assistant is unable to do that.

Here's my current docker-compose.yaml (simplified a bit to remove some non-zwave device stuff):

 services:
   homeassistant:
     image: "ghcr.io/home-assistant/home-assistant:stable"
     container_name: homeassistant
     restart: unless-stopped
     privileged: false
     volumes:
       - ./config:/config
     ports:
       - 8123:8123
   zwavejs:
     image: zwavejs/zwave-js-ui:latest
     container_name: zwavejs
     restart: unless-stopped
     tty: true
     stop_signal: SIGINT
     ports:
       - 8091:8091 # web interface
     devices:
       - /dev/serial/by-id/usb-Zooz_800_Z-Wave_Stick_533D004242-if00:/dev/zwave

In HA, I have it configured to talk to ws://172.22.0.2:3000 which works as long as that's the IP for zwavejs.

If I instead enter ws://zwavejs:3000 it doesn't work, even though I can enter the HA container and do ping zwavejs and it works fine.

How do I get HA to resolve the container name to an IP address so I can stop hardcoding it?

Add docker network to your compose file and add the containers to it

use extra hosts and also set specific ip addresses per container.

version: '3'

networks:
  local_network:
    ipam:
      driver: default
      config:
        - subnet: ${SUBNET}.0/24

        
services:
  ha:
    container_name: ha
    image: homeassistant/home-assistant:${HA_VERSION}
    volumes:
      - ${DOCKER_FOLDER}/${HA_FOLDER}/config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    environment:
      PROXY_IP: ${SUBNET}.1
      TZ: America/New_York
      HOST_IP: ${HOST_IP}
    network_mode: "host"
    depends_on:        
      - zwave
      - mariadb
    extra_hosts:
      - "zwave:${SUBNET}.3"
      - "mqtt:${SUBNET}.6"
      - "mariadb:${SUBNET}.4"
      - "nas:${HOST_IP}"
  zwave:
    container_name: zwave
    image: zwavejs/zwave-js-ui:${ZWAVE_VERSION}
    volumes:
      - ${DOCKER_FOLDER}/${ZWAVE_FOLDER}:/usr/src/app/store
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyACM0:/dev/ttyACM0
    restart: unless-stopped
    environment:
      TZ: America/New_York
    networks: 
      local_network:
        ipv4_address: ${SUBNET}.3
    ports:
      - 3000:3000
      - 8091:8091

i was thinking something simplier

 services:
   homeassistant:
     image: "ghcr.io/home-assistant/home-assistant:stable"
     container_name: homeassistant
     hostname: homeassistant
     restart: unless-stopped
     privileged: false
     volumes:
       - ./config:/config
     networks:
       homeassistant:
     ports:
       - 8123:8123
   zwavejs:
     image: zwavejs/zwave-js-ui:latest
     container_name: zwavejs
     hostname: zwavejs
     restart: unless-stopped
     tty: true
     stop_signal: SIGINT
     networks:
       homeassistant:
     ports:
       - 8091:8091 # web interface
     devices:
       - /dev/serial/by-id/usb-Zooz_800_Z-Wave_Stick_533D004242-if00:/dev/zwave
networks:
  homeassistant:
    driver: bridge

How do you handle mDNS if not in host network mode?

MDNS is seperate from OP question. I prefer containers communicate on docker network.

You can still use host networking or whatever networking. This just allows containers to connect via hostname

Sorry, I understood the OP was asking about hostnames, but I was wondering how you use the above configs and still have mDNS/dns-sd/zeroconf discovery work for devices that advertise on the host network. e.g. an mdns reflector? It's bridge in both cases and that's isolated.

If you can ping (and thus resolve) using the name zwavejs but ws://zwavejs:3000 doesn't work that seems like something else, right? Do the logs show it attempting to connect and failing?

Using the above OP's config I see this, so it's resolving correctly:

homeassistant  | 2026-05-29 14:39:16.450 DEBUG (MainThread) [homeassistant.components.zwave_js] Failed to connect to Z-Wave JS server: Cannot connect to host zwavejs:3000 ssl:default [Connect call failed ('172.27.0.2', 3000)]

But in my case port 3000 isn't open because I haven't enabled the websocket (or configured the serial port)

homeassistant:/config# nmap -p 3000,8091 172.27.0.2
Starting Nmap 7.97 ( https://nmap.org ) at 2026-05-29 14:42 +0000
Nmap scan report for zwavejs.ha-net-test_default (172.27.0.2)
Host is up (0.000031s latency).

PORT     STATE  SERVICE
3000/tcp closed ppp
8091/tcp open   jamlink
MAC Address: C6:6D:85:18:06:9F (Unknown)