0

I am trying to connect the node js container with the Redis container, I am facing an issue when I run the node-js container and try to connect Redis. I tried most of the solutions from the web, still not able to fix the connection refused issuer.


> Node js creating the Redis client: below code works locally good, without the container.

const redis = require('redis')
const redisClient = redis.createClient({
  host: "127.0.0.1",
  port: "6379"
})


> running Redis from the latest image.

docker run -d --name redis -p 6379:6379 redis

> Error:

[nodemon] starting `node index.js`

events.js:377

      throw er; // Unhandled 'error' event

      ^


Error: connect ECONNREFUSED 127.0.0.1:6379

    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1148:16)

Emitted 'error' event on RedisClient instance at:

    at RedisClient.on_error (/usr/src/app/node_modules/redis/index.js:342:14)

    at Socket.<anonymous> (/usr/src/app/node_modules/redis/index.js:223:14)

    at Socket.emit (events.js:400:28)

    at emitErrorNT (internal/streams/destroy.js:106:8)

    at emitErrorCloseNT (internal/streams/destroy.js:74:3)

    at processTicksAndRejections (internal/process/task_queues.js:82:21) {

  errno: -111,

  code: 'ECONNREFUSED',

  syscall: 'connect',

  address: '127.0.0.1',

  port: 6379

}
nagaraj
  • 797
  • 1
  • 6
  • 29
  • Does this answer your question? [Can't connect Redis server to nodejs, Docker compose](https://stackoverflow.com/questions/59448292/cant-connect-redis-server-to-nodejs-docker-compose) – Molda Sep 21 '21 at 09:26
  • i changed as mentioned in above link, still have error:) – nagaraj Sep 21 '21 at 09:51
  • Have you tried bridging the network using the host network (i.e `--network=host`). https://docs.docker.com/network/host/ – akortex Sep 21 '21 at 11:25
  • as I have mentioned above, I am not using any compose file to create Redis, I am directly fetching from docker hub. – nagaraj Sep 21 '21 at 12:00

0 Answers0