1

I want to use redis-image in docker-hub.

so, i make docker-compose.yml file like this

version: "3.7"

services:
  backend:
    container_name: test-server
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ".:/app"
      - "/app/node_modules"
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=development
    stdin_open: true
    tty: true
    depends_on:
      - redis
  redis:
      image: redis
      command: redis-server --port 6379
      container_name: redis
      hostname: redis
      labels:
        - "name=redis"
        - "mode=standalone"
      ports:
        - 6379:6379

For docker internal connection, I found some few answers in stackoverflow

fail to link redis container to node.js container in docker

so, I redis.createClient("redis://0.0.0.0:6739"); like this

when, I build docker image. and run docker

In this container Error Error: connect ECONNREFUSED 127.0.0.1:6379

Initially, I think the url error, but i change to redis://localhost:6378(just change port)

I got same error, like this Error Error: connect ECONNREFUSED 127.0.0.1:6379

Seonghun
  • 161
  • 7
  • check https://stackoverflow.com/questions/8754304/redis-connection-to-127-0-0-16379-failed-connect-econnrefused – James Jun 24 '22 at 13:42
  • You need to use the Redis container's Compose name `redis` as a hostname. Neither 0.0.0.0 ("listen on all interfaces") nor 127.0.0.1/localhost ("this container") will work. You can safely remove the `container_name:` and `hostname:` options from your Compose setup, they're not required for this connectivity. – David Maze Jun 24 '22 at 14:14

0 Answers0