I have three replicated containers running RabbitMQ in a Swarm Mode service. Each container acts as a RabbitMQ node to create a RabbitMQ cluster. The docker service create
for this is as follows:
docker service create -e RABBITMQ_ERLANG_COOKIE='mysecretcookie' --replicas 4 --network rnet -p 15672:15672 -p 5672:5672 rabbitmq
I'm able to successfully create a RabbitMQ cluster using rabbitmqctl <hostname> join_cluster
on each of the slave nodes thereafter.
My problem is that if a swarm node goes down, Docker starts a new container on a different node however the container has a different random hostname.
Since RabbitMQ uses the hostname to identify RabbitMQ cluster nodes, it doesn't recognise the new hostname on the new container so it assumes that the original node is indefinitely down.
I tried using the new templating feature in Docker 1.13 which allows you to create static hostnames by specifying --hostname="{{.Node.ID}}-{{.Service.Name}}"
within docker service create
. However, you cannot currently discover containers based on this custom hostname so a RabbitMQ cluster can't be created in this way.
I want to be able to have RabbitMQ automatically re-join a cluster node after Docker starts running a new container. Is this possible?