dockergoredisredigo

Redigo: Redis connection refused panic


Here 2 services in docker-compose.yml:

logger-service:
...
# Here main service using Redis by Redigo

redis:
    image: redis:alpine
    ports:
      - "6380:6379"
    environment:
      REDIS_PASSWORD: password

    volumes:
      - ./db_data/redis:/data
    restart: unless-stopped

Logger service trying to connect to Redis instance by the following func:

func connectToRedis() (redis.Conn, error) {
    conn, err := redis.Dial("tcp", "redis:6379",
        redis.DialPassword("password"),
    )
    if err != nil {
        log.Println("Error connecting Redis: ", err)
        return nil, err
    }

    _, err = redis.String(conn.Do("PING"))
    if err != nil {
        log.Println("Redis not pinged:", err)
        return nil, err
    }

    log.Println("Connected to Redis")

    return conn, nil
}

Logger service docker log contains panic:

2025-04-08 14:06:39 goroutine 1 [running]:
2025-04-08 14:06:39 log.Panic({0xc00015bf20?, 0x4d2452?, 0xc00011b2b0?})
2025-04-08 14:06:39     C:/Program Files/Go/src/log/log.go:432 +0x5a
2025-04-08 14:06:39 main.main()
2025-04-08 14:06:39     C:/Users/vbulash/VSCode/go-micro/logger-service-redis/cmd/api/main.go:27 +0x9a
2025-04-08 14:06:45 2025/04/08 11:06:45 Error connecting Redis:  ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
2025-04-08 14:06:45 2025/04/08 11:06:45 ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?
2025-04-08 14:06:45 panic: ERR AUTH <password> called without any password configured for the default user. Are you sure your configuration is correct?

main.go:27 here is just a call of connectToRedis.

Why my password provided by DialPassword is simply ignored, as far as I see in panic log?

P.S. When I comments out DialPassword, connect ends successfully, but it also means that my password ignored and Redis remains completely unsecured


Solution

  • Thanks to @Peter - REDIS_PASSWORD in docker environment is non-standard, so Redis service during installation just ignores it. Later I will write command tag in Redis service turning on authentication