Install RabbitMQ on Dokku

In a previous post, i explained how to package RabbitMQ and several plugins in a Docker Container, so this will be a followup which shows you how to deploy and configure the RabbitMQ Container on a dokku host.

This Post will not explain how to install Dokku itself – so i assume you have a Dokku environment configured and ready.

Prepare your deployment

The following Dockerfile uses the official RabbitMQ Container and extending it by activating the management and the MQTT plugin. If you don’t need MQTT the you can delete the line  RUN rabbitmq-plugins enable --offline rabbitmq_mqtt .

Now create a new directory containing the Dockerfile with the above contents and initialize a git repository.

Then add your dokku server via  git remote add dokku dokku@myserver.com:myhostname

DO NOT PUSH(!) your changes now, you have to do some configuration first!

Prepare your Dokku-App

Create an app

Create an app with the dokku apps:create <appname>  where appname is the sub domain of your dokku app.

Set the Docker configuration

Now we have to set several docker options for the container. This options are necessary to expose the needed service ports and also to preserve the RabbitMQ configuration and data after a restart.

Depending on the services you want to use, you have to expose multiple ports. With the above Dockerfile, RabbitMQ is using the following ports: 1883:mqtt, 5672:amqp, 15672:remote admin, 25672:clustering.

The remote admin port will be bound to your application url (default behaviour of dokku). For the other ports, like mqtt, you have to configure the port forwarding manually. So just add a forwarding for the mqtt port:

dokku docker-options:add  deploy,run "-p 1883:1883"

The syntax is quite clear so you should be able to add other ports if you have to. 😉

Next point is the persistence of the data. If you miss the next step, all your configurations will be gone after a restart. Just add a directory on your dokku host (i’ll use /opt/rabbitmq/) and mount this directory to the RabbitMQ app:

dokku docker-options:add  deploy,run "-v /opt/rabbitmq:/var/lib/rabbitmq"

Another important step is to set the hostname as RabbitMQ will prefix the configurations with this. Unfortunately, docker is generating a random hostname on every container start, so we have to fix it to a certain value.

dokku docker-options:add  deploy,run "--hostname rabbitmqserver"

All done? Lets check if the configuration is in place by executing  dokku docker-options <yourappname> . The result should look like this:

Looks good? Cool

Deploy and test your App

Now we have everything in place to deploy the app. Deploy the app via  git push dokku master . The app should now be deployed. Open a web browser and connect to  http://<appname>.<yourserver>:15672 – if everything is ok you should see the RabbitMQ admin login – use guest: guest as login and have fun with RabbitMQ 🙂