docker-compose简单构建redis集群

首先要有redis-cluster镜像、redis-cli镜像
一、构建redis-cluster镜像链接

二、构建redis-cli镜像链接
1、编写docker-comper文件

vim redis.yml
version: '3'
services:
   redis1:
      image: redis-cluster
      environment:
        - REDIS_PORT=7001
      ports:
        - 7001:7001
        - 17001:17001
   redis2:
      image: redis-cluster
      environment:
        - REDIS_PORT=7002
      ports:
        - 7002:7002
        - 17002:17002
   redis3:
      image: redis-cluster
      environment:
        - REDIS_PORT=7003
      ports:
        - 7003:7003
        - 17003:17003
   redis4:
      image: redis-cluster
      environment:
        - REDIS_PORT=7004
      ports:
        - 7004:7004
        - 17004:17004
   redis5:
      image: redis-cluster
      environment:
        - REDIS_PORT=7005
      ports:
        - 7005:7005
        - 17005:17005
   redis6:
      image: redis-cluster
      environment:
        - REDIS_PORT=7006
      ports:
        - 7006:7006
        - 17006:17006

2、记得要有docker-compose文件,启动docker-compose文件,可能会出现延时报错,不必管

docker-compose -f redis.yml up -d

3、查看docker容器,redis是否启动

docker-compose -f redis.yml ps

4、启动集群

docker run --rm -it redis-cli  redis-cli --cluster create 10.0.0.41:7001 10.0.0.41:7002 10.0.0.41:7003 10.0.0.41:7004 10.0.0.41:7005 10.0.0.41:7006 --cluster-replicas 1

docker-compose简单构建redis集群_第1张图片
5、测试集群是否正确,记得测试主机要有客户端
docker-compose简单构建redis集群_第2张图片
成功

你可能感兴趣的:(docker,redis)