Docker Community Forums

Share and learn in the Docker community.

Node-red error connecting to Redis

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, 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
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: -


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

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 and not localhost:6379.

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?

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

What does that mean?

If this not working, then:

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:

  container_name: pbu_node-red
  image: djtbrit/node-red
    - TZ=UTC/UTC
    - "1880:1880"
    - node-red-data
    - pbu-net
    - redis
    - influx
  container_name: pbu_redis
  image: redis
    - "6379:6379"
    - pbu-net
    - redis-data



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.


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.