I cannot connect to Redis image from a Node image within Docker

First all was working great with default configuration until I hit one memory limit, then I needed to add a Redis configuration file (latest, 7.0). In this file bind is set to 127.0.0.1 with default port, so I tried that. I also changed that to bind 0.0.0.0 but I got the same error.

Now in for my environment variables I’m putting: redis//redis:6379 or redis:6379 so here is my configuration (docker-compose.yml):

version: '3.7'
services:
  classified-ads:
    container_name: classified-ads
    depends_on:
      - redis-service
    ports:
      - 3000:3000
    build:
      context: ./
    # restart: unless-stopped
    environment:
      - REDIS_URI=redis:6379
      - INSIDE_DOCKER=wahoo
  # our custom image 
  redis:
      container_name: redis-service
      build:
        context: ./docker/redis/
      privileged: true
      command: sh -c "./init.sh"
      ports:
        - '6379:6379'
      volumes: 
        - ./host-db/redis-data:/data/redis:rw

The error I’m getting is bloated and is from my client which is ioredis but it is clearly a connection error. (ioredis wrapped with Fastify/redis, so it is a failed promise that is very verbose but not clearly indicative, but it’s 100% a connection error).

I checked Redis logs piped to Docker and it is running fine.

I found the solution. While the default redis:alpine image use configuration with protection_mode yes I was using a new configuration with protection_mode no. I also removed the bind 'address' all together.

And reconnected normally from other services with redis:port as usual.
all thanks to docker - Cannot connect to redis container in app but can ping to that container - Stack Overflow

1 Like