Docker Community Forums

Share and learn in the Docker community.

Node-RED and Home Assistant - can't get it working

Hi,

I am at my wits end trying to get Node-RED connected to Home Assistant server. I have HA and NR running in docker containers on a NUC.
These are the docker-compose.yml files for both:

version: "3"
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock
    devices:
      # Conbee II Zigbee device on USB
      - /dev/ttyACM1:/dev/ttyACM1
    restart: unless-stopped
    network_mode: host
version: "3.7"
services:
  node-red:
    container_name: nodered
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Brussels
    ports:
      - "1880:1880"
    restart: unless-stopped
    volumes:
      - ./data:/data

Node-RED version:

nodered     | 30 Oct 14:03:23 - [info] Node-RED version: v2.1.3
nodered     | 30 Oct 14:03:23 - [info] Node.js  version: v14.18.1
nodered     | 30 Oct 14:03:23 - [info] Linux 5.11.0-38-generic x64 LE

Whith this configuration, NR tries to connect to HA without success:

nodered     | 30 Oct 14:03:24 - [info] Starting flows
nodered     | 30 Oct 14:03:24 - [info] Started flows
nodered     | 30 Oct 14:03:24 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123

As advised by some in the HA forums, I changed the NR docker-compose.yml as follows:

version: "3.7"
services:
  node-red:
    container_name: nodered
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Brussels
#    ports:
#      - "1880:1880"
    restart: unless-stopped
    volumes:
      - ./data:/data
    network_mode: host

Doing so, NR connects to HA:

nodered     | 30 Oct 14:08:57 - [info] Server now running at http://127.0.0.1:1880/
....
nodered     | 30 Oct 14:08:58 - [info] Starting flows
nodered     | 30 Oct 14:08:58 - [info] Started flows
nodered     | 30 Oct 14:08:58 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered     | 30 Oct 14:08:58 - [info] [server:Home Assistant] Connected to http://192.168.2.60:8123

Great, problem solved :grinning: ! Well, no…

In this configuration, I cannot connect anymore to NR via the 1880 port…
But the port seems to be up and listening…

$ sudo lsof -i :1880
COMMAND     PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node-red 429417 jiheffe   19u  IPv4 1682621      0t0  TCP *:1880 (LISTEN)

What am I missing here ?