要搭建Docker Redis集群,可以按照以下步驟進行操作:
version: '3'
services:
redis-master:
image: redis
container_name: redis-master
ports:
- "6379:6379"
networks:
- redis-net
redis-slave1:
image: redis
container_name: redis-slave1
ports:
- "6380:6379"
command: redis-server --slaveof redis-master 6379
networks:
- redis-net
redis-slave2:
image: redis
container_name: redis-slave2
ports:
- "6381:6379"
command: redis-server --slaveof redis-master 6379
networks:
- redis-net
networks:
redis-net:
docker-compose up -d
現在你已經成功搭建了一個簡單的Docker Redis集群。你可以通過訪問主節點的6379端口來訪問Redis集群。