0

I have to dockerize a node app which used redis-server. I used docker-compose and official image of redis there.

But, when I run docker compose up, after hitting the API it gives me an error like this

[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379 docker-redis | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)

I used ioredis package, I give REDIS_PORT and REDIS_HOST as the argument of new Redis()

const Redis = require('ioredis');
const { promisify } = require('util');

const publisher = new Redis({
  port: process.env.REDIS_PORT,
  host: process.env.REDIS_HOST,
});


here REDIS_HOST='redis' and REDIS_PORT=6379

and this is my docker-compose file

version: '3'
services:
  app:
    container_name: docker-redis
    restart: always
    build: .
    ports:
      - '3000:3000'
    links:
      - redis
    # depends_on:
    #   - redis

  redis:
    container_name: redis
    image: redis:latest
    ports:
      - '6379:6379'
    command: ['redis-server', '--bind', 'redis', '--port', '6379']

0 Answers0