redis / redis-doc

Redis documentation source code for markdown and metadata files, conversion scripts, and so forth
Other
2.31k stars 1.72k forks source link

Improve documentation for using Redis with Docker in multi-network scenarios #2408

Open samantagavare opened 1 year ago

samantagavare commented 1 year ago

I've encountered connectivity issues when using Redis master, slave, and Sentinel instances in a Docker environment with multiple networks. The problem arises when the Sentinels return the IP address of the Redis master within the same network, while the application tries to connect to the Redis master through Redis Sentinel using IP address from the external network. This leads to connection failures.

Example of docker-compose, which causes the problem:

version: '3.9'

volumes:
  redis-master-0-data:
  redis-slave-0-data:
  redis-slave-1-data:

services:
  redis-slave-0:    
    container_name: redis-slave-0
    env_file:
      - redis.env
    build:
      context: ./redis/slave
      dockerfile: Dockerfile-slave
    volumes:
      - redis-slave-0-data:/dat
    depends_on:
      - redis-master-0
    restart: always
    ports:
      - "6380:6379"
    networks:
      - redis
      - my-network

  redis-slave-1:    
    container_name: redis-slave-1
    build:
      context: ./redis/slave 
      dockerfile: Dockerfile-slave
    env_file:
      - redis.env
    volumes:
      - redis-slave-1-data:/dat
    depends_on:
      - redis-master-0
    restart: always
    ports:
      - "6381:6379"
    networks:
      - redis
      - my-network

  redis-master-0:    
    container_name: redis-master-0
    build:
      context: ./redis/master
      dockerfile: Dockerfile-master
    env_file:
      - redis.env
    volumes:
      - redis-master-0-data:/data
    ports:
      - "6379:6379"
    restart: always
    networks:
      - redis
      - my-network

  redis-sentinel-0:
    container_name: redis-sentinel-0
    env_file:
      - redis.env
    build:
      context: ./redis/sentinel
      dockerfile: Dockerfile
    links:
      - redis-master-0
      - redis-slave-0
      - redis-slave-1
    ports:
      - "26379:26379"
    networks:
      - redis
      - my-network

  redis-sentinel-1:
    container_name: redis-sentinel-1
    env_file:
      - redis.env
    build:
      context: ./redis/sentinel
      dockerfile: Dockerfile
    links:
      - redis-master-0
      - redis-slave-0
      - redis-slave-1
    ports:
      - "26380:26379"
    networks:
      - redis
      - my-network

  redis-sentinel-2:
    container_name: redis-sentinel-2
    env_file:
      - redis.env
    build:
      context: ./redis/sentinel
      dockerfile: Dockerfile
    links:
      - redis-master-0
      - redis-slave-0
      - redis-slave-1
    ports:
      - "26381:26379"
    networks:
      - redis
      - my-network

networks:
  my-network:
    external: true
  redis:
    driver: bridge

Although I have found a solution to my problem (by removing redis network), I believe the Redis documentation can be improved to provide more guidance on using Redis with Docker in scenarios involving multiple networks. This would help users to better understand the potential issues and the recommended configurations for seamless communication between Redis instances and applications.

Some specific areas where the documentation could be enhanced include:

Please consider enhancing the Redis documentation to cover these aspects and help users avoid similar issues in the future.

itamarhaber commented 1 year ago

Hello @samantagavare

Thanks for proposing this improvement to the documentation - I'm moving this issue to the docs repo.

Would you like to contribute this content? If so, please feel free to make a PR.