Redis cluster with docker swarm using docker compose

时光怂恿深爱的人放手 提交于 2019-12-21 13:09:25

问题


I'm just learning docker and all of its goodness like swarm and compose. My intention is to create a Redis cluster in docker swarm.

Here is my compose file -

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

If I add the network: - host then none of the containers start, if I remove it then the containers start but when I try to connect it throws an error like CLUSTERDOWN Hash slot not served.

Specs -

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

回答1:


This seems to work for me, network config from here :

version: '3.6'

services:
  redis:
    image: redis:5.0.3
    command:
      - "redis-server"
      - "--cluster-enabled yes"
      - "--cluster-config-file nodes.conf"
      - "--cluster-node-timeout 5000"
      - "--appendonly yes"
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
    networks:
      hostnet: {}

networks:
  hostnet:
    external: true
    name: host

Then run for example: echo yes | docker run -i --rm --entrypoint redis-cli redis:5.0.3 --cluster create 1.2.3.4{1,2,3}:6379 --cluster-replicas 0

Replace your IPs obviously.




回答2:


For anyone struggling with this unfortunately this can't be done via docker-compose.yml yet. Refer to this issue Start Redis cluster #79. The only way to do this is by getting the IP address and ports of all the nodes that are running Redis and then running this command in any of the swarm nodes.

# 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



回答3:


here is repo for redis cluster

https://github.com/jay-johnson/docker-redis-cluster/blob/master/docker-compose.yml



来源:https://stackoverflow.com/questions/49979226/redis-cluster-with-docker-swarm-using-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!