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

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.

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

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:

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:

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.

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