Node-red error connecting to Redis via docker-compose

I have the following setup: -

RPi 4 with 4GB ram
Ubuntu 20:04 server
Docker version 19.03.11, build 42e35e6

I've got everything contained in docker containers created via docker-compose .

The problem I have is when I configure the host in the node-red node-red-contrib-redis instance node I get this message:

pbu_node-red | [ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
pbu_node-red |     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)

I've created the node-red image myself using this Dockerfile

FROM nodered/node-red
RUN echo 'Installing required nodes...'
WORKDIR /usr/src/node-red
RUN npm install node-red-contrib-redis
RUN npm install node-red-contrib-influxdb

The redis image is straight from Docker Hub. I know Docker creates its own network when you deploy the containers via docker-compose and I believe the hostname I should have in the redis instance is redis:6379. Unfortunately this gives the same error.

My docker-compose file looks like this:

ersion: '3.7'
services:
  redis:
    container_name: pbu_redis
    image: djtbrit/redis
#    ports:
#      - "6379:6379"
    networks:
      - pbu-net
#    environment:
#      - REDIS_URL=redis://redis:6379/0
    volumes:
      - redis-data
  influx:
    container_name: pbu_influx
    image: influxdb
    ports:
      - "8086:8086"
    networks:
      - pbu-net
    volumes:
      - infux-data
  grafana:
    container_name: pbu_grafana
    image: grafana/grafana
    ports:
      - "80:3000"
    networks:
      - pbu-net
    depends_on:
      - redis
      - influx
    volumes:
      - grafana-data:/var/lib/grafana
  node-red:
   container_name: pbu_node-red
    image: djtbrit/node-red
    environment:
      - TZ=UTC/UTC
      - REDIS_URL=redis://redis:6379/0
    ports:
      - "1880:1880"
    volumes:
      - node-red-data
    links:
      - redis
    networks:
      - pbu-net
    depends_on:
      - redis
      - influx

volumes:
  node-red-data:
  redis-data:
  influx-data:
  grafana-data:

I've spent many days trying to resolve this and I'm not progressing at all...

Any help gratefully received.

The error says it all. It is trying to connect to 127.0.0.1 which is the node red container. You need to point it at the redis container you have set up. Assuming the compose file has setup the networking working correctly of course.

Hi dceejay, I've set the hostname to redis, which is the name of the service that I have in the docker-compose.yaml.

I'll upload the Node-Red flow when I get back to my desk.

The simple flow as promised which shows that the redis node is configured to connect to redis which is the name of the redis service in the docker-compose.yaml as described earlier.

[{"id":"faa6dd89.ddde8","type":"redis-instance","z":"43c4864.f907978","server":"412e2394.62f55c","name":"","topic":"redis","location":"flow","block":false,"x":400,"y":80,"wires":[]},{"id":"412e2394.62f55c","type":"redis-config","z":"","name":"redis:6378","options":"{}","cluster":false,"optionsType":"json"}]```

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.