# Node-red error connecting to Redis via docker-compose

**URL:** <https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941>\
**Category:** General\
**Created:** [7 June 2020 14:57 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941 "2020-06-07T14:57:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maninmadrid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maninmadrid/32/23504_2.png) [@Maninmadrid](https://discourse.nodered.org/u/Maninmadrid)\
**Post date:** [7 June 2020 14:57 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941/1 "2020-06-07T14:57:35Z")

</div>

I have the following setup: -

```auto
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:

```auto
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

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [7 June 2020 15:28 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941/2 "2020-06-07T15:28:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maninmadrid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maninmadrid/32/23504_2.png) [@Maninmadrid](https://discourse.nodered.org/u/Maninmadrid)\
**Post date:** [7 June 2020 16:07 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941/3 "2020-06-07T16:07:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Maninmadrid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/maninmadrid/32/23504_2.png) [@Maninmadrid](https://discourse.nodered.org/u/Maninmadrid)\
**Post date:** [7 June 2020 18:20 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941/4 "2020-06-07T18:20:48Z")

</div>

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.

````auto
[{"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"}]```
````

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 August 2020 18:20 UTC](https://discourse.nodered.org/t/node-red-error-connecting-to-redis-via-docker-compose/27941/5 "2020-08-06T18:20:56Z")

</div>

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