Shvalb
Shvalb

Reputation: 1933

Running Redis in a cluster mode on a Docker container fails to CLUSTER MEET

I'm trying to run on my local machine (MacOS) Redis in a cluster mode via Docker container.

Those are my steps:

docker network create redis-cluster

I run 3 master nodes redis-7001, redis-7002 & redis-7003 (No slaves) as follow:

docker run -d --rm \
  --name redis-7001 \
  -e ALLOW_EMPTY_PASSWORD=yes \
  --net redis-cluster \
  -p 7001:6379 -p 17001:17001 \
  -v ~/LuckyrhinoStudios/docker/redis_cluster/7001:/data redis \
  redis-server --port 6379 \
  --cluster-enabled yes \
  --cluster-config-file /data/nodes.conf \
  --cluster-node-timeout 5000 \
  --appendonly yes \
  --protected-mode no \
  --bind 0.0.0.0 \
  --cluster-announce-ip host.docker.internal \
  --cluster-announce-port 7001 \
  --cluster-announce-bus-port 17001

For the -cluster-announce-ip I've tried using my machine's internal ip address (e.g: 192.168.2.11 as well to host.docker.internal).

Then I try to create the cluster:

docker exec -it redis-7001 redis-cli --cluster create \
  host.docker.internal:7001 host.docker.internal:7002 host.docker.internal:7003 \
  --cluster-replicas 0 --verbose

And It's doesn't "CLUSTER MEET" them, the output on the cli looks like this:

docker exec -it redis-7001 redis-cli --cluster create \                            
  host.docker.internal:7001 host.docker.internal:7002 host.docker.internal:7003 \
  --cluster-replicas 0 --verbose -t 4000
>>> Performing hash slots allocation on 3 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
M: 9c925299fc50e6639cd6686b34714cb640bc219b host.docker.internal:7001
   slots:[0-5460] (5461 slots) master
M: a747fbaae0d00d45e8129ceb012dedd6de9c7d0e host.docker.internal:7002
   slots:[5461-10922] (5462 slots) master
M: b120c5dbf48ec21e577192f7db045b0df1db71e6 host.docker.internal:7003
   slots:[10923-16383] (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.....................

And it never returns.

I see in each nodes.conf file the follownig:

b120c5dbf48ec21e577192f7db045b0df1db71e6 host.docker.internal:7003@17003,,tls-port=0,shard-id=c210b6352ea5304d55ddcb8a00de75b888c57ec4 myself,master - 0 0 3 connected 10923-16383
vars currentEpoch 3 lastVoteEpoch 0

Which I believe is registered correctly.

The bottom line is that I cannot register the 3 nodes to the cluster when I'm using my machine's internal ip 192.168.2.11 or docker's host.docker.internal and Redisson fails because it detects there is a configuration issue.

Any idea what I'm missing here?

Upvotes: 0

Views: 45

Answers (1)

Shvalb
Shvalb

Reputation: 1933

So the thing is that MacOS runs Docker via a VM and that makes problems accessing the host from within the container.

The solution is actually very simple, it turns out that from the Docker UI app you can enable "Enable Host Networking" which does the trick and allow accessing your host ip address from within the container and from then on everything is simple and works as a charm!

Upvotes: 0

Related Questions