1、配置容器
touch redis-contian.sh
for port in $(seq 1 3); \
do \
docker create --name redis-node${port} --net host -v /data/redis-data/node${port}:/data redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-${port}.conf --port 639${port} --requirepass 123456
done
2、启动容器
touch redis-start.sh
docker start redis-node1 redis-node2 redis-node3
3、进入容器并组建集群
# 这里以 redis-node1 实例为例
docker exec -it redis-node1 /bin/bash
# 192.168.60.52 为物理机ip
redis-cli --cluster create 192.168.60.52:6391 192.168.60.52:6392 192.168.60.52:6393 --cluster-replicas 0
4、移除集群
touch rm-redis.sh
for port in $(seq 1 3); \
do \
docker stop redis-node${port}
docker rm redis-node${port} -v
rm -rf /data/redis-data/*
done