0
0
RabbitmqHow-ToBeginner ยท 3 min read

How to Install RabbitMQ on Docker: Quick Setup Guide

To install rabbitmq on Docker, run docker run -d --hostname my-rabbit --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management. This command pulls the official RabbitMQ image with the management plugin and starts the container exposing ports for messaging and the web UI.
๐Ÿ“

Syntax

The basic syntax to run RabbitMQ on Docker is:

  • docker run: Command to start a new container.
  • -d: Runs the container in detached mode (in the background).
  • --hostname: Sets the container's hostname.
  • --name: Assigns a name to the container for easy reference.
  • -p: Maps container ports to host ports (5672 for messaging, 15672 for management UI).
  • rabbitmq:3-management: The official RabbitMQ image with the management plugin.
bash
docker run -d --hostname my-rabbit --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
๐Ÿ’ป

Example

This example runs RabbitMQ with the management plugin enabled. It exposes port 5672 for messaging and 15672 for the web management interface. You can access the management UI by opening http://localhost:15672 in your browser.

bash
docker run -d --hostname my-rabbit --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
Output
Unable to find image 'rabbitmq:3-management' locally 3-management: Pulling from library/rabbitmq ... Digest: sha256:... Status: Downloaded newer image for rabbitmq:3-management <container_id>
โš ๏ธ

Common Pitfalls

Common mistakes when installing RabbitMQ on Docker:

  • Not mapping ports correctly, so you cannot connect to RabbitMQ or access the management UI.
  • Using the default RabbitMQ image without the 3-management tag, which lacks the web UI.
  • Not running the container in detached mode, which blocks your terminal.
  • Forgetting to remove old containers with the same name, causing conflicts.
bash
docker run -d --name rabbitmq -p 5672:5672 rabbitmq
# This image lacks the management UI

# Correct way:
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
๐Ÿ“Š

Quick Reference

OptionDescription
-dRun container in background (detached mode)
--hostnameSet container hostname
--nameAssign a name to the container
-p 5672:5672Map RabbitMQ messaging port
-p 15672:15672Map RabbitMQ management UI port
rabbitmq:3-managementOfficial RabbitMQ image with management plugin
โœ…

Key Takeaways

Use the official RabbitMQ image with the '3-management' tag to get the web UI.
Map ports 5672 and 15672 to access messaging and management UI respectively.
Run the container in detached mode with '-d' to keep your terminal free.
Assign a container name with '--name' to manage it easily.
Remove old containers with the same name to avoid conflicts.