dockerrabbitmqdocker-swarm-mode

How to configure rabbitmq.config inside Docker containers?


I'm using the official RabbitMQ Docker image (https://hub.docker.com/_/rabbitmq/)

I've tried editing the rabbitmq.config file inside the container after running

docker exec -it <container-id> /bin/bash

However, this seems to have no effect on the rabbitmq server running in the container. Restarting the container obviously didn't help either since Docker starts a completely new instance.

So I assumed that the only way to configure rabbitmq.config for a Docker container was to set it up before the container starts running, which I was able to partly do using the image's supported environment variables.

Unfortunately, not all configuration options are supported by environment variables. For instance, I want to set {auth_mechanisms, ['PLAIN', 'AMQPLAIN', 'EXTERNAL']} in rabbitmq.config.

I then found the RABBITMQ_CONFIG_FILE environment variable, which should allow me to point to the file I want to use as my conifg file. However, I've tried the following with no luck:

docker service create --name rabbitmq --network rabbitnet \
-e RABBITMQ_ERLANG_COOKIE='mycookie' --hostname = "{{Service.Name}}{{.Task.Slot}}" \
--mount type=bind,source=/root/mounted,destination=/root \
-e RABBITMQ_CONFIG_FILE=/root/rabbitmq.config rabbitmq

The default rabbitmq.config file containing:

[ { rabbit, [ { loopback_users, [ ] } ] } ]

is what's in the container once it starts

What's the best way to configure rabbitmq.config inside Docker containers?


Solution

  • the config file lives in /etc/rabbitmq/rabbitmq.config so if you mount your own config file with something like this (I'm using docker-compose here to setup the image)

    volumes:
    - ./conf/myrabbit.conf:/etc/rabbitmq/rabbitmq.config
    

    that should do it.

    In case you are having issues that the configuration file get's created as directory, try absolute paths.