Running RabbitMQ with Docker

James Louie
Pragmatic Programming
3 min readNov 15, 2018

Short post today about how to setup RabbitMQ (and just about any other supporting containers) for local docker development. Refer back to my previous post to learn more about RabbitMQ.

Prerequisite

A complete guide can be found on Docker Hub Website for RabbitMQ, but you really just need a few key commands to get up and running.

Why use Docker?

Before Docker, you would have to track down their website, find the download section, make sure we had all the requirements and dependencies, install some executable or service, and then finally get to run the thing.

The great thing about docker is that it defines a pre-built environment that has all of the dependencies needed, as well as keeps itself isolated to a non-user defined space, separating out your usual work space from your tooling work space.

Docker centralizes the management of all your supporting systems into the command line, allowing you to manage them in one place. This allows you to create, start, stop and inspect each of the instances running your system at any given time.

Docker containers can be closer to your production systems if you’re running something like Swarm or Kubernetes for container orchestration where each of your applications is a container on a machine.

For more on Docker, read a previous post.

Installation

First we’ll need to create the container for RabbitMQ. I’m choosing the version that contains the management plugin, which has a UI to manage the RabbitMQ service.

Behind the scenes, Docker is pulling the image (a file that defines how to create an instance of the application) from Docker Hub, downloads it to your local machine, and then starts the application with the given commands.

Using the Management UI

Once your container is running, it should respond with the container ID or name, and you should be able to access it through the browser by navigating to http://localhost:15672/.

Common Docker Commands

  • docker image ls Lists out the images available on your system.
  • docker container ls Lists out the containers currently running on your machine. Containers are the actual running instances of the image specified to create it.
  • docker start <image name> Starts the image with the specified commands when initially created. For example when we created RabbitMQ, we specified -d to run in detached mode and -p to open up ports. We would run the command, docker start rabbitmq.
  • docker stop <image name> Stops the image.
  • docker prune Removes all images that are unused. Alternatively you can append the -a option to specify to remove all images, not just “dangling” images — those that have some associations with current containers.

And that should wrap things up. You should know how to create a local docker instance of RabbitMQ on your machine and the commands to manage the lifetime of the docker container. Now get coding!

--

--

James Louie
Pragmatic Programming

Developer looking to make the code a little more clean