导致原因是开启host网络模式,不能设置ports 。所以注释掉ports就可以了
- version: "3"
- services:
- redis-master1:
- image: redis # 基础镜像
- container_name: node1 # 容器名称
- working_dir: /config # 切换工作目录
- environment: # 环境变量
- - PORT=6391 # 会使用config/nodes-${PORT}.conf这个配置文件
- #ports: # 映射端口,对外提供服务
- #- 6391:6391 # redis的服务端口
- #- 16391:16391 # redis集群监控端口
- stdin_open: true # 标准输入打开
- tty: true # 后台运行不退出
- network_mode: host # 使用host模式
- privileged: true # 拥有容器内命令执行的权限
- volumes:
- - /mydata/redis-cluster/config:/config #配置文件目录映射到宿主机
- entrypoint: # 设置服务默认的启动程序
- - /bin/bash
- - redis.sh
- redis-master2:
- image: redis
- working_dir: /config
- container_name: node2
- environment:
- - PORT=6392
- #ports:
- #- 6392:6392
- #- 16392:16392
- stdin_open: true
- network_mode: host
- tty: true
- privileged: true
- volumes:
- - /mydata/redis-cluster/config:/config
- entrypoint:
- - /bin/bash
- - redis.sh
- redis-master3:
- image: redis
- container_name: node3
- working_dir: /config
- environment:
- - PORT=6393
- #ports:
- #- 6393:6393
- #- 16393:16393
- stdin_open: true
- network_mode: host
- tty: true
- privileged: true
- volumes:
- - /mydata/redis-cluster/config:/config
- entrypoint:
- - /bin/bash
- - redis.sh
- redis-slave1:
- image: redis
- container_name: node4
- working_dir: /config
- environment:
- - PORT=6394
- #ports:
- #- 6394:6394
- #- 16394:16394
- stdin_open: true
- network_mode: host
- tty: true
- privileged: true
- volumes:
- - /mydata/redis-cluster/config:/config
- entrypoint:
- - /bin/bash
- - redis.sh
- redis-slave2:
- image: redis
- working_dir: /config
- container_name: node5
- environment:
- - PORT=6395
- #ports:
- #- 6395:6395
- #- 16395:16395
- stdin_open: true
- network_mode: host
- tty: true
- privileged: true
- volumes:
- - /mydata/redis-cluster/config:/config
- entrypoint:
- - /bin/bash
- - redis.sh
- redis-slave3:
- image: redis
- container_name: node6
- working_dir: /config
- environment:
- - PORT=6396
- #ports:
- #- 6396:6396
- #- 16396:16396
- stdin_open: true
- network_mode: host
- tty: true
- privileged: true
- volumes:
- - /mydata/redis-cluster/config:/config
- entrypoint:
- - /bin/bash
- - redis.sh
修改完以后顺利搭建成功