There are a lots of good options if you want to run a RabbitMQ cluster in docker. Here's an solution that only rely on docker official images ๐
The main benifit with this approach is that you can use any version of RabbitMQ, which is maintaied by docker and will be up-to-date with future releases.
For information on how to achieve clustering using peer discovery, refer to the rabbitmq official website.
- Cluster Formation and Peer Discovery
- RabbitMQ Docker-compose Sample: Peer Discovery with Consul
- Consul Deploy Sample
- RabbitMQ Configuration Sample
-
Apply Auto-Clustering
- Enable clustering plug-in;
rabbitmq_peer_discovery_consul
- Apply useful setting to rabbitmq.conf, from "peer discovery with consul sample"
- Enable clustering plug-in;
-
Change container image tag to specific version
- Update image tag of RabbitMQ:
3-management
to3-management-alpine
- Update image tag of HAProxy:
1.7
tolts-alpine
- Add image tag of Consul:
latest
to1-debian-11
- Update image tag of RabbitMQ:
-
Add some plugins for RabbitMQ
rabbitmq_management_agent
rabbitmq_peer_discovery_consul
rabbitmq_tracing
rabbitmq_web_mqtt
rabbitmq_web_stomp
-
Add
depends_on
of containers;Consul(consul) >> HAProxy(haproxy) >> RabbitMQ(rabbit)
-
Add
always
restart policy for all containers. -
Add container-shared network as
bridge mode
:rabbitmq-network
> # Clone repository
> git clone https://github.com/pseudojo/docker-rabbitmq-cluster.git
> cd docker-rabbitmq-cluster
>
> # Start development
> docker compose up
>
> # Start long-options with daemon
> docker compose --env-file ./.env --file ./docker-compose.yml up -d
>
> # How to scale-up RabbitMQ : --scale rabbit=<NUMBER>
> docker compose up -d --scale rabbit=7
> # ... or
> docker compose --env-file ./.env --file ./docker-compose.yml up -d --scale rabbit=7
Most things will be how you expect:
- The default username and password are
rabbitmq
/changeme
- The broker accepts connections on
localhost:5672
- AMQP :
localhost:5672
- MQTT :
localhost:1883
- STOMP :
localhost:15672
- AMQP :
- The Management interface is found at
localhost:15672
> # check containers
> docker compose ps
>
> # trailing logs with latest 100 lines for all containers
> docker compose logs --tail=100 -f
The .env
file contains environment variables that can be used to change the default username, password and virtual host.
This docker-compose.yml
file comes with the latest version of HAProxy, an open source software that provides a high availability load balancer and proxy server.
It should be fairly easy to add a port mapping
for the individual containers if it is desired to connect to a specific broker node.
For monitoring, Connect to HAProxy Statistics Page. URL is localhost:1936
.
> cd docker-rabbitmq-cluster
>
> # Stop rabbitmq-cluster smoothly.
> docker compose down
>
> # Stop rabbitmq-cluster quickly. (3 seconds timeout)
> docker compose down --timeout 3 --remove-orphans
>
> # Purge all
> docker compose down --rmi all --remove-orphans --timeout 3
I wrote a blog post that explains some of the ideas behind this repo.