使用docker compose和docker swarm的Redis集群

Soh*_*pta 6 docker docker-compose docker-swarm alpine-linux

我只是在学习docker及其所有优点,例如swarm和compose。我的意图是在docker swarm中创建Redis集群。

这是我的撰写文件-

version: '3'

services:
  redis:
    image: redis:alpine
    command: ["redis-server","--appendonly yes","--cluster-enabled yes","--cluster-node-timeout 60000","--cluster-require-full-coverage no"]
    deploy:
      replicas: 5
      restart_policy:
        condition: on-failure
    ports:
      - 6379:6379
      - 16379:16379

networks:
  host:
    external: true
Run Code Online (Sandbox Code Playgroud)

如果添加,network: - host则不会启动任何容器,如果将其删除,则容器会启动,但是当我尝试连接时会引发类似的错误CLUSTERDOWN Hash slot not served

眼镜 -

Windows 10

Docker Swarm Nodes -
2 Virtual Box VMs running Alpine Linux 3.7.0 with two networks

VirtualBox VM Network - 
eth0 - NAT
eth1 - VirtualBox Host-only network

Docker running inside the above VMs - 
17.12.1-ce
Run Code Online (Sandbox Code Playgroud)

Soh*_*pta 2

不幸的是,对于任何为此苦苦挣扎的人来说,这还无法完成docker-compose.yml。参考这个问题启动Redis集群#79。执行此操作的唯一方法是获取运行 Redis 的所有节点的 IP 地址和端口,然后在任何 swarm 节点中运行此命令。

# Gives you all the command help
docker run --rm -it thesobercoder/redis-trib 

# This creates all master nodes
docker run --rm -it thesobercoder/redis-trib create 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 

# This creates slaves nodes. Note that this requires at least six nodes running master
docker run --rm -it thesobercoder/redis-trib create --replicas 1 172.17.8.101:7000 172.17.8.102:7000 172.17.8.103:7000 172.17.8.104:7000 172.17.8.105:7000 172.17.8.106:7000
Run Code Online (Sandbox Code Playgroud)