- redis cluster는 최소 3개의 레디스 노드로 구성이 되어야함
- 해당 예제에서는 레디스 노드들을 각각 6300, 6301, 6302번 포트로 실행
- 실행되는 포트 번호를 변경하려면 compose파일의 포트와 redis*.conf 파일의 포트를 수정
version: "3.9"
services:
redis-cluster:
image: redis:latest
container_name: redis-cluster
volumes:
- ./redis.conf:/usr/local/etc/redis.conf
command: redis-server /usr/local/etc/redis.conf
ports:
- 6300:6300
- 6301:6301
- 6302:6302
redis-node1:
network_mode: "service:redis-cluster"
image: redis:latest
container_name: redis-node1
volumes:
- ./redis1.conf:/usr/local/etc/redis.conf
command: redis-server /usr/local/etc/redis.conf
redis-node2:
network_mode: "service:redis-cluster"
image: redis:latest
container_name: redis-node2
volumes:
- ./redis2.conf:/usr/local/etc/redis.conf
command: redis-server /usr/local/etc/redis.conf
redis-node3:
network_mode: "service:redis-cluster"
image: redis:latest
container_name: redis-node3
volumes:
- ./redis3.conf:/usr/local/etc/redis.conf
command: redis-server /usr/local/etc/redis.conf
redis-cluster-entry:
network_mode: "service:redis-cluster"
image: redis:latest
container_name: redis-cluster-entry
command: redis-cli --cluster create 127.0.0.1:6300 127.0.0.1:6301 127.0.0.1:6302 --cluster-yes
depends_on:
- redis-cluster
- redis-node1
- redis-node2
- redis-node3