由 Docker Redis 组成的 Redis cluster 在 macOS 上无法成功创建

2020-08-27 12:24:52 +08:00
 JasonLaw

启动多个实例

for i in {7000..7002}
do
   docker run -d --name Redis-cache-cluster-node-${i} \
      --network=host \
      -v Redis-cache-cluster-node-${i}_data:/data \
      redis:6.0.6 \
      redis-server --port ${i} --cluster-enabled yes --cluster-config-file nodes.conf -- cluster-node-timeout 5000 --appendonly yes
done

创建 cluster

docker run -it --rm --network=host redis \
redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002

在 Ubuntu 上面,是可以成功创建 cluster 的,但是在 macOS 上面却不行,一直卡在“Waiting for the cluster to join”,到底是为什么呢?


关于网络问题,我已经查阅了ip - Docker container doesn't expose ports when --net=host is mentioned in the docker run command - Stack OverflowBlock/disallow --net=host (host networking) on Mac OS · Issue #2716 · docker/for-mac,并且尝试过使用-p ${i}:${i} -p $((${i} + 10000)):$((${i} + 10000))替换--network=host,结果还是不行。

2229 次点击
所在节点    Docker
6 条回复
windghoul
2020-08-27 13:37:53 +08:00
创建一个虚拟网络,然后进到 docker 里面执行 cli 命令
windghoul
2020-08-27 13:38:41 +08:00
whileFalse
2020-08-27 14:01:13 +08:00
先看看你的 Docker for Mac 有没有开代理。
JasonLaw
2020-08-27 15:02:43 +08:00
@windghoul #2
@whileFalse #3

我想确认一下我理解的是不是正确的。--network=host 不行是因为 macOS 不支持,单纯使用-p ${i}:${i} -p $((${i} + 10000)):$((${i} + 10000))替换--network=host 不行是因为 redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 中的 127.0.0.1 (因为它们这三个容器都有自己的“动态”IP 地址)。对吗?
windghoul
2020-08-27 17:23:10 +08:00
@JasonLaw #4 我之前创建的,在 linux 上,也不能用宿主机的 ip 进行集群添加,只能用它的虚拟 ip 进行添加,具体的原因我还没来得及研究
qfdk
2020-08-27 19:22:30 +08:00
你要用 host 代替你的 127.0.0.1 你这个属于容器内部的通信 link 估计也可以

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/701868

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX