3

i'm trying to use redis connection on local node js application but it throwing an error ---

events.js:183 throw er; // Unhandled 'error' event ^

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)

enter image description here

enter image description here

running none docker image

running docker image

Rudra
  • 109
  • 2
  • 7
  • 1
    your question is not clear... you need to provide more details, like the Dockerfile used for redis and node, the commands you are trying to run, how you started the docker container, etc. – Exadra37 Feb 17 '19 at 00:04
  • Are you even exposing the port? – Carlos Feb 17 '19 at 01:18

3 Answers3

0

If I understand correctly, you are running node inside a Docker container. This node process is trying to reach redis instance running at localhost.

This does not work, because container (node) has its own network stack, and 127.0.0.1 does not point to the host.

In this case you'd need to either

  1. Run redis in its own container (and use e.g. docker-compose) OR
  2. Change the Node connection host for redis from localhost (or 127.0.0.1) to your host IP address. See How to get the primary IP address of the local machine on Linux and OS X? for finding IP address
Mika Vatanen
  • 3,782
  • 1
  • 28
  • 33
0

You are trying to connect to the wrong port. As the docker ps command says, the port where redis is listening is 32768. Connecting to that port should solve your issue.

See the official docker documentation (in particular the flag -p) for more information about customizing port listening.

Polpetta
  • 495
  • 1
  • 3
  • 13
  • var redis = require("redis"), redis_client = redis.createClient("redis://127.0.0.1:32768"); ------------------------------------------------- Thanks this did the work done! – Rudra Feb 17 '19 at 19:45
  • If this was the correct answer, then mark it as the solution please! – Polpetta Feb 17 '19 at 19:58
0

You can also resolve this error by redoing your Docker container, just add the "-p 6379: 6379" flag. Example (Redis with persistent date):

docker run --name some-redis -p 6379:6379 -d redis redis-server --appendonly yes