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:

  2. Create Docker network

docker network create --driver overlay rediscluster

  1. Create Docker service for Redis
    docker service create
    –name redis_6379
    –network rediscluster
    –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
&& ruby redis-trib.rb create --replicas 1’

  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.