Redis cluster create hang at "Waiting for cluster to join" using Docker swarm

I tried to create Redis cluster in a swarm cluster with 6 nodes, but it becomes infinite wait

  1. My servers:
    docker-swarm-1 192.168.56.101
    docker-swarm-2 192.168.56.102
    docker-swarm-3 192.168.56.103
    docker-swarm-4 192.168.56.104
    docker-swarm-5 192.168.56.105
    docker-swarm-6 192.168.56.106

  2. Create Docker network

docker network create --driver overlay rediscluster

  1. Create Docker service for Redis
    docker service create
    –name redis_6379
    –network rediscluster
    –publish=6379:6379
    –replicas=6
    –mount type=bind,src=/redis/redis_6379/,target=/data/
    redis redis-server /data/redis.conf

  2. Add more port pairing to Docker service for Redis cluster

docker service update --publish-add 16379:16379 redis_6379

  1. Create Redis cluster

docker run -i --rm ruby sh -c '\

gem install redis
&& wget http://download.redis.io/redis-stable/src/redis-trib.rb
&& ruby redis-trib.rb create --replicas 1 192.168.56.101:6379 192.168.56.102:6379 192.168.56.103:6379 192.168.56.104:6379 192.168.56.105:6379 192.168.56.106:6379’

  1. Result:
    The last step always become a infinite wait.
    “Waiting for the cluster to join…”

To troubleshoot, I logon to the docker container and verified the Redis cluster port 16379 is accessible among the Docker container.

Can someone advise me which part has went wrong?
This procedure works when I used docker-compose, instead of Docker swarm.

I’ve found the answer to this problem myself. The problem is we cannot use the Docker server IP, we need to use command “docker network inspect rediscluster” to find out the IP assigned to each container and use that to create the Redis cluster.