要搭建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集群。