# Node-red error connecting to Redis

**URL:** <https://forums.docker.com/t/node-red-error-connecting-to-redis/95137>\
**Category:** Docker Hub\
**Created:** [June 6, 2020, 11:12am UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137 "2020-06-06T11:12:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![djtbrit](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@djtbrit](https://forums.docker.com/u/djtbrit)\
**Post date:** [June 6, 2020, 11:12am UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/1 "2020-06-06T11:12:14Z")

</div>

Hi, I’m new to Docker and am struggling with an issue that I’m supposing is easy to fix - I hope so!

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

```

The problem I have is when I add a redis input node to the palette I’m not too sure what to use as the host; I’ve tried redis, ioredis, localhost, 127.0.0.1 and the IP of my machine and they all return the same error in the node-red log.

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

```

Any ideas what the problem can be? I’m sure its obvious but I’ve searched everywhere without success to find the solution.

This is my (very simple) flow: -

```
[{"id":"453536fa.587998","type":"redis-out","z":"94d077d5.7a1748","server":"199115fd.fe49da","command":"publish","name":"","topic":"message/play","x":520,"y":80,"wires":[]},{"id":"5a1ff379.3b738c","type":"redis-instance","z":"94d077d5.7a1748","server":"d44a8dae.3fea6","name":"","topic":"redis","location":"flow","block":false,"x":490,"y":40,"wires":[]},{"id":"199115fd.fe49da","type":"redis-config","z":"","name":"redis","options":"{}","cluster":false,"optionsType":"json"},{"id":"d44a8dae.3fea6","type":"redis-config","z":"","name":"redis","options":"{}","cluster":false,"optionsType":"json"}]

```

Any help gratefully received.

Dockerfile for djtbrit/node-red is: -

```
1 FROM nodered/node-red
2 RUN echo 'Installing required nodes...'
3 WORKDIR /usr/src/node-red
4 RUN npm install node-red-contrib-redis
5 RUN npm install node-red-contrib-influxdb

```

An finally my docker-compose.yaml file is: -

 ![image](https://global.discourse-cdn.com/docker/original/3X/b/f/bfb47cc17afff587aaa2eba46c8b7c0c632f69d5.png)

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [June 6, 2020, 12:33pm UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/2 "2020-06-06T12:33:38Z")

</div>

The issue is a lack of undersanding about scopes/contexts…  
Localhost in a container is local to the container, not to the host the docker engine is running.

Since you use docker compose, you will have a default network created for you and the containers connected to it. This network should have a build in dns server. Though, it might become necessary to declare your own network and assign you containers to them in your docker-compose.yml. Not sure, I never worked with the default networks. For container to container communication use the servicename. You named your redis service `redis`, thus your node-red service needs to use `redis:6379` to communicate with it. Container to container communication does not use published ports, they can call other containers ports directly without any restrictions.

If this is still not working… did you build the redis image yourself by any chance? If so, make sure when it startes the redis process, that it binds redis to 0.0.0.0:6379 and not localhost:6379.

---

<div class="post-metadata">

**Author:** ![djtbrit](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@djtbrit](https://forums.docker.com/u/djtbrit)\
**Post date:** [June 6, 2020, 3:01pm UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/3 "2020-06-06T15:01:43Z")

</div>

Thanks for the prompt reply and advice. The Redis container is from Docker Hub and untouched by me.

The Redis container has the port 6369 exposed and I think it should be available to the network created by docker-compose.

Do you think I need to add the -h redis option to the Node-Red container?

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [June 6, 2020, 3:19pm UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/4 "2020-06-06T15:19:38Z")

</div>

The Dockerfile for the latest tag uses “EXPOSE 6379”.  
I used it in the past, it should bind the port to 0.0.0.0:6379

> [@djtbrit](#):
>
> Do you think I need to add the -h redis option to the Node-Red container?

What does that mean?

> [@meyay](#):
>
> For container to container communication use the servicename. You named your redis service `redis` , thus your node-red service needs to use `redis:6379` to communicate with it.

If this not working, then:

> [@meyay](#):
>
> Though, it might become necessary to declare your own network and assign you containers to them in your docker-compose.yml

---

<div class="post-metadata">

**Author:** ![djtbrit](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@djtbrit](https://forums.docker.com/u/djtbrit)\
**Post date:** [June 6, 2020, 4:38pm UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/5 "2020-06-06T16:38:05Z")

</div>

I’ve updated the `docker-compose.yaml` file so that it now has a network in it and added it to each container but it still doesn’t work. The redis node for node-red doesn’t let you set the port as it assumes you want to use the standard 6379 - which I do. if I add the value `redis:6369` as the host I get the same error message.

My docker compose file now has in it:

```auto
node-red:
  container_name: pbu_node-red
  image: djtbrit/node-red
  environment:
    - TZ=UTC/UTC
  ports:
    - "1880:1880"
  volumes:
    - node-red-data
  networks:
    - pbu-net
  depends_on:
    - redis
    - influx
redis:
  container_name: pbu_redis
  image: redis
  ports:
    - "6379:6379"
  networks:
    - pbu-net
  volumes:
    - redis-data

volumes:
  node-red-data:
  redis-data:

networks:
  pbu-net:

```

---

<div class="post-metadata">

**Author:** ![meyay](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/meyay/32/34000_2.png) [@meyay](https://forums.docker.com/u/meyay)\
**Post date:** [June 6, 2020, 9:05pm UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/6 "2020-06-06T21:05:56Z")

</div>

> [@djtbrit](#):
>
> The redis node for node-red doesn’t let you set the port as it assumes you want to use the standard 6379 - which I do. if I add the value `redis:6369` as the host I get the same error message.

If the hostname needs to be specified without the port, then do so. You made the image, you should know how your stuff is supposed to work.

I shared with you how things work in docker networks. Making it work is on you.

---

<div class="post-metadata">

**Author:** ![djtbrit](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@djtbrit](https://forums.docker.com/u/djtbrit)\
**Post date:** [June 8, 2020, 9:55am UTC](https://forums.docker.com/t/node-red-error-connecting-to-redis/95137/7 "2020-06-08T09:55:05Z")

</div>

FIXED:

I discovered that the Node-Red `redis instance` nodes have a dependancy on `ioredis` and I read the API documentation and saw that the redis connection can be a JSON object with a host property.

I edited the `options` dropdown and added the host of the redis container name and voila - it all worked as expected. It appears that the `Name` box is just a description of the connection.

![image](https://global.discourse-cdn.com/docker/original/3X/a/e/ae3da4ac4c2129c735d1cf7271f924c1c34c0795.png)
