Logo AppDev24 Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Docker

Docker RabbitMQ Container

Updated on Aug 15, 2024

Are you looking to set up a RabbitMQ container using Docker on your MacOS machine? Look no further! In this article, we'll walk you through the process of creating and configuring a Docker RabbitMQ container, including setting environment variables, starting the container, and testing the broker.

Step 1: Create an Environment File

The first step is to create an environment file that will store our RabbitMQ user password.

.env

DB_PASSWORD=Password1234

This file will be used to set the RABBITMQ_DEFAULT_PASS environment variable in our Docker container.

Step 2: Create a Docker Compose File

Next, we'll create a Docker compose file that defines our RabbitMQ container.

rabbitmq-docker-compose.yml

version: '3.9'

services:
  rabbitmq:
    # Apple M1 Chip
    # platform: linux/amd64
    image: rabbitmq:3.11-management
    container_name: rabbitmq
    hostname: rabbitmq
    restart: always
    env_file:
      - .env
    environment:
      RABBITMQ_DEFAULT_USER: rabbitmq
      RABBITMQ_DEFAULT_PASS: $DB_PASSWORD
      RABBITMQ_DEFAULT_VHOST: my_vhost
    ports:
      - 5672:5672
      - 15672:15672
    volumes:     
      - rabbitmq_datadir:/var/lib/rabbitmq
    networks:
      - rabbitmq-network

networks:
  rabbitmq-network:
    driver: bridge

volumes:
  rabbitmq_datadir:

This file defines a single service, rabbitmq, which uses the official RabbitMQ 3.11-managemet image and maps port 15672 on your local machine to port 15672 in the container.

Step 3: Start the Container

Now that we have our environment file and Docker compose file set up, it's time to start the container! Run the following command:

docker-compose -f rabbitmq-docker-compose.yml up -d

This will start the container in detached mode, meaning it will run in the background.

Step4: Test RabbitMQ Container

Now we will create a queue and some messages. 

Note: you should have rabbitmqadmin Client installed locally.

db_password=Password1234

rabbitmqadmin -H 127.0.0.1 -P 15672 -V my_vhost -u rabbitmq -p ${db_password} list vhosts
rabbitmqadmin -H 127.0.0.1 -P 15672 -V my_vhost -u rabbitmq -p ${db_password} declare queue name=my-new-queue durable=true
rabbitmqadmin -H 127.0.0.1 -P 15672 -V my_vhost -u rabbitmq -p ${db_password} publish exchange=amq.default routing_key=my-new-queue payload="hello, world" properties="{\"delivery_mode\":2}"

Test the queue & messages -

rabbitmqadmin -H 127.0.0.1 -P 15672 -V my_vhost -u rabbitmq -p ${db_password} list queues
rabbitmqadmin -H 127.0.0.1 -P 15672 -V my_vhost -u rabbitmq -p ${db_password} get queue=my-new-queue ackmode=ack_requeue_false

Also we can access RabbitMQ management console UI from browser at http://127.0.0.1:15672 with username rabbitmq and corresponding password.

RabbitMQ management plugin
RabbitMQ management plugin

Step 5: Stop the Container

Finally, we can stop the container by running the following command:

docker-compose -f rabbitmq-docker-compose.yml down

This will stop the container and remove it from memory.

That's it! We've successfully created and configured a Docker RabbitMQ container.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles