Setup without Compose - Zerpet/docker-rabbitmq-cluster GitHub Wiki
Using purely Docker consists in spawning the containers manually one by one. In this approach, it is required to link the containers together or to attach them to a user-defined network. In this example, Docker links are used.
Starting a container with a RabbitMQ with docker requires, at the very least, the following parameters:
RABBITMQ_ERLANG_COOKIE
-- This can be any string--hostname server1
-- This option is required for RabbitMQ clustering
First node
An example to start a RabbitMQ disc node would be:
docker run --hostname server1 -e RABBITMQ_ERLANG_COOKIE="secret" --name rabbitmq-server1 -p 15672:15672 zerpetfakename/rabbitmq-cluster:3.7
This command launches a single instance of a RabbitMQ node and forwards the port in 15672
in the localhost
to the container. This port can be used to access the management UI in a browser using 127.0.0.1:15672
.
Second node
Once the first node is up and running, the second node has to be linked to the first node and it must include the variable RABBITMQ_ERLANG_COOKIE
with the same value as the first node. An example would be:
docker run --hostname server2 --name rabbitmq-server2 -e CLUSTER_WITH=server1 -e RABBITMQ_ERLANG_COOKIE="secret" -p 15673:15672 --link rabbitmq-server1:server1 zerpetfakename/rabbitmq-cluster:3.7
The second node should start up normally; once the RabbitMQ node is started, the script to join the cluster will wait for 20 seconds to allow initialization of the node; then it will add the node to the cluster if it's not already part of it.
Third node
Adding a third node is possible specifying the same Erlang cookie and links to the previous two nodes. It is also possible to specify a RAM node using the variable ENABLE_RAM=true
. An example of a command to spawn a third node would be:
docker run -e ENABLE_RAM=true --hostname server3 --name rabbitmq-server3 -e CLUSTER_WITH=server1 -e RABBITMQ_ERLANG_COOKIE="secret" -p 15674:15672 --link rabbitmq-server1:server1 --link rabbitmq-server2:server2 zerpetfakename/rabbitmq-cluster:3.7
Once the node is started, it will check if it's part of a cluster and it will join if it's not a member already. Please review the Limitations section to learn about a known limitation with RAM nodes.