Docker Install Rabbitmq

2/13/2022by admin


  1. RabbitMQ is the most widely deployed open-source message broker. In the below section, I will describe how easily you can install and run RabbitMQ using Docker. At first, we need to create an EC2 instance and then connect to it via Putty or Terminal. After that, we need to install the docker using following command. Sudo yum install docker -y.
  2. (line 21-22) Configures Docker to get the RabbitMQ and Management docker images using instructions from the docker rabbitmq website (line 23) Creates a Docker container called “rabbitmq” and forwards ports 15672, 1883, and 5672 (line 24) Enables the MQTT Plugin (line 25)Configures Docker to get the NGINX HTTP container.
  • Linux Machine
  • Docker installed.
  • Docker compose installed.

Setting up Docker Compose

Docker pull rabbitmq: 3-management The image ID is a SHA256 digest covering the image's configuration and layers, and Docker uses a content-addressable image store. For the web application, we will map port 15672 and the message broker port 5672 by using below command. Using the RabbitMQ Docker Image. The RabbitMQ container registry includes a variety of images for different platforms.In this article, we will use the RabbitMQ image with a tag 3-management, which is a Docker image with the RabbitMQ management plugin installed and enabled by default.

If you want to make your code more portable and share the same version of RabbitMQ with your developer colleagues, I highly recommend using Docker.

Create a docker-compose.yml file into your project root folder.

Install and up rabbitmq container.

That’s it. This configuration will take a pull of rabbitmq:3.8.14-managment image from docker hub and install on your machine.

You can access your rabbitm mq ui from http://localhost:15672. Default user and password would be guest, guest.

What is the issue with above container?

Docker Install Rabbitmq

As per above, rabbitmq container is up and running file. You would also able to connect ui and create queue, publish message and consume message with rabbitmq consumer.

Docker Install RabbitmqRabbitmq

Docker Install Rabbitmqadmin

But there is issue, The Data Persistent issue. Means if you recreate a container with above configuration then the new container will be up and your old data will be lost , that could me major issue as per you application structure.

How to fix data persistent issue?

Install Rabbitmq In Docker

So as per the document statement on official rabbitmq website is:

One of the important things to note about RabbitMQ is that it stores data based on what it calls the “Node Name”, which defaults to the hostname. What this means for usage in Docker is that we should specify -h/--hostname explicitly for each daemon so that we don’t get a random hostname and can keep track of our data:

Install Rabbitmq Docker Windows

Means whenever we are run up command in docker-compose, it will create a new container with random hostname and linked to default network. And the old container will be erased with its data. So this is we need to fix.

Docker Install Rabbitmq

Here is updated docker-compose.yml file that would fix this issue for you.

  • image: where we tell Docker which image to pull. We’re using an Alpine implementation of RabbitMQ with the management plugin. The Alpine distro is the one you’ll want to use if you want to save disk space.
  • container_name: this represents the container created from the image above.
  • ports: the list of ports that will be mapped from the container to the outside world, for interacting with the queue and the web UI.
  • volumes: where we map the log and data from the container to our local folder. This allows us to view the files directly in their local folder structure instead of having to connect to the container.
  • networks: where we specify the network’s name that the container will be using. This helps to separate container network configurations.
  • hostname: hostname of the container so, that it would get random name for each creation.
Docker Install Rabbitmq

This configuration would resolve your issue. Please check and let us if you still facing issue on comment section.

Set RabbitMQ with data persistent, with Docker Compose
Comments are closed.