Confused by networking modes - can't get Node-RED connected correctly

Docker newbie here (well not completely, but then :wink:)

I have several docker containers running under Ubuntu on a NUC without issues: Pihole, Samba, Mosquitto, Zwave2MQTT, MariaDB, Portainer, Home Assistant…

Trying to set up Node-RED in its container, I run in the following issue: depending of my configuration in docker-compose.yml, I run into two different situations:

Case 1 - with ports: statement

    ports:
      - "1880:1880"
  • I can connect to Node-RED web interface on port 1880
  • Node-RED does not connect to either HA or MQTT broker
nodered     | 31 Oct 11:01:28 - [info] Server now running at http://127.0.0.1:1880/
nodered     | 31 Oct 11:01:28 - [info] Starting flows
nodered     | 31 Oct 11:01:29 - [info] Started flows
nodered     | 31 Oct 11:01:29 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered     | 31 Oct 11:01:59 - [info] [mqtt-broker:Mosquitto MQTT] Connection failed to broker: http://192.168.2.60

Case 2 - with network_mode: statement

    network_mode: host
  • I can not connect to Node-RED web interface on port 1880
  • Node-RED does connect to HA and MQTT broker
nodered     | 31 Oct 11:06:30 - [info] Server now running at http://127.0.0.1:1880/
nodered     | 31 Oct 11:06:30 - [info] Starting flows
nodered     | 31 Oct 11:06:30 - [info] Started flows
nodered     | 31 Oct 11:06:30 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered     | 31 Oct 11:06:30 - [info] [mqtt-broker:Mosquitto MQTT] Connected to broker: http://192.168.2.60
nodered     | 31 Oct 11:06:30 - [info] [server:Home Assistant] Connected to http://192.168.2.60:8123

Here is my complete docker-compose.yml:


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
# To use network_mode, comment out ports: statements
#    network_mode: host

Can someone explain me what I am missing here?