gpt4 book ai didi

docker - 使用 docker compose 与 docker swarm 建立 Redis 集群

转载 作者:行者123 更新时间:2023-12-01 23:04:32 26 4
gpt4 key购买 nike

我正在学习 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

如果我添加 network: - host ,则没有任何容器启动,如果我删除它,则容器启动,但当我尝试连接时,它会抛出类似 CLUSTERDOWN Hash slot 的错误未提供服务

规范 -

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

最佳答案

这似乎对我有用,网络配置来自 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

然后运行例如: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

明显替换你的IP。

关于docker - 使用 docker compose 与 docker swarm 建立 Redis 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49979226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com