1

I am trying to set up a dockerized redis cluster spanning multiple host machines. In my curretn setup I have two hosts with public ip addresses and start a similar configuration on both, this config consists of a compose.yml:

services:
  redis-cluster:
    container_name: node-redis
    build: 
      context: ../../
      dockerfile: deployment/node/cluster-dockerfile
    restart: always
    ports:
      - "7000:7000"
      - "7001:7001"
      - "7002:7002"

    networks:
      node_net:
        ipv4_address: 10.20.0.6
networks:
  node_net:
    driver: bridge
    ipam:
     config:
       - subnet: 10.20.0.0/16
         gateway: 10.20.0.1

which is identical on both hosts. The Dockerfile uses supervisord to start 3 redis instances (on ports 7000, 7001 and 7002) as such:

FROM ubuntu:20.04

RUN apt update && \
  DEBIAN_FRONTEND=noninteractive apt install -y redis-server supervisor 

COPY ./deployment/production-node/cluster-files/node1 /app/cluster-files
COPY ./deployment/production-node/cluster-files/node1/supervisord.conf /etc/supervisor/supervisord.conf 

CMD supervisord -c /etc/supervisor/supervisord.conf && \
sleep infinity

Each redis instance is configured as such:

port <port number> 
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
masterauth pass
requirepass pass
protected-mode no
bind 0.0.0.0
unixsocket /tmp/redis.sock
loglevel debug
logfile "serverlog.7000.txt"
cluster-config-file nodes7000.conf
cluster-announce-ip <public ip of host machine>
cluster-announce-port <port number>

After running docker compose up on both hosts and redis instances stating correctly i try to use redis-cli to create cluster as such:

redis-cli -a pass --cluster create <host1-ip>:7000 <host1-ip>:7001 \
<host1-ip>:7002 <host2-ip>:7000 <host2-ip>:7001 <host2-ip>:7002 \
--cluster-replicas 1

This results in waiting infinitely for the cluster to join.

After some consideration I figured that this may be caused by not exposing proper cluster bus ports in docker to solve this I changed the compsoe file to list additional ports:

      - "7000:7000"
      - "7001:7001"
      - "7002:7002"
      - "17000:17000"
      - "17001:17001"
      - "17002:17002"

And added this line to the redis.conf files:

cluster-port 17000 <and 17001, 17002 respective to the other port used by instance>

After those changes I am not even able to connect to a single instance and get an instant connection refused when tryin to create cluster.

As of now I am not sure how to solve this problem and would be gratefull for any hints as to how properly configure this kind of redis cluster without starting containers in the host network mode.

MarkusSPE
  • 81
  • 1
  • 10

0 Answers0