RabbitMQ on Docker
RabbitMQ on Docker using official image is easy. It is well documented here.
Note: This is to be used only on developer machine.
Running RabbitMQ official docker image
Pull docker image
docker pull rabbitmq:3
Now run it
docker run -d --hostname my-rabbit -p 5672:5672 —name rabbitMQ rabbitmq:3
Note:
--hostname: RabbitMQ stores data based on what it calls as "node-name" which defaults to hostname. In docker, this is a problem. We may end up with a different hostname each time we run it. So it is better to provide a hostname to use.
-p : we expose port 5672 inside docker container as 5672 on localhost. Other ports it exposes are 4369/tcp, 5671/tcp, 25672/tcp
--name: this is name of image
Running RabbitMQ with UI
In above docker image, we do not get RabbitMQ UI. Or the management console.
So we use a different image to get a management console too.
docker run -d --hostname local-rabbit -p 5672:5672 -p 15672:15672 --name rabbitMQ rabbitmq:3-management
Now open management console as
Passwords are default: guest/guest
Note:
- rabbit queue declared as "transient" is lost on restart.
- rabbit queue declared as "durable" is not lost on container restart. However data within it is lost.
- any type of rabbit queue is lost when container is removed and recreated.
Other important configurations
Adding a vhost
Use environment variable
-e RABBITMQ_DEFAULT_VHOST=my_vhost
Adding default user and password
Not sure if as a developer you would want to do it. But you can use environment variable.
-e RABBITMQ_DEFAULT_USER=user -e RABBITMQ_DEFAULT_PASS=password
Comments
Post a Comment