rabbitmq docker container .erlang.cookie is not set from RABBITMQ_ERLANG_COOKIE env variable

I am trying to set up a rabbitmq cluster on with aws container service. I need the /var/lib/rabbitmq/.erlang.cookie to be the same on all nodes. So for all my rabbitmq containers when they are run I pass in a RABBITMQ_ERLANG_COOKIE environment variable which according to documentation here https://hub.docker.com/_/rabbitmq/ should be written into /var/lib/rabbitmq/.erlang.cookie.

When I inspect my running container I can see that environment variable RABBITMQ_ERLANG_COOKIE=QOKWQHQKXXTBIEAOPWKE is present but when i cat /var/lib/rabbitmq/.erlang.cookie I get a different value AYMNAPKRPCPJVPFYAJZX.

As a result all rabbitmq containers have different .erlang.cookie and cannot form a cluster.

Why isn't the cookie from environment variable set? What could I be missing here?

I am using rabbitmq:3.6.9-alpine image.


I run into this thread when search very similar problem, but my env var is ERLANG_COOKIE, after I changed to use RABBITMQ_ERLANG_COOKIE, it's working like a charm

Here comes my docker-compose about rabbitmq, ${HOST} will be replaced with value set in .env file which lives in the same folder as docker-compose.yml

rabbitmq:
  image: rabbitmq:3-management
  ports:
    - "15672:15672"
    - "25672:25672"
    - "5672:5672"
    - "4369:4369"
  environment:
    - RABBITMQ_ERLANG_COOKIE='takeMyCookies'
  hostname: "${HOST}"

Take a look at the cookie value

root@prod-03:/# cat ~/.erlang.cookie
'takeMyCookies'
root@prod-03:/# cat /var/lib/rabbitmq/.erlang.cookie
'takeMyCookies'

I had the same error until I configured the cookie value correctly and removed the '-' character from it.

Another way to set it is RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="-setcookie cookie-value"


There is a bug in version 3.9 of the RabbitMQ docker image where the RABBITMQ_ERLANG_COOKIE value is not being written to the /var/lib/rabbitmq/.erlang.cookie file in the container. The bug is identified here -> https://github.com/docker-library/rabbitmq/pull/502.

One solution is to use some other version of the RabbitMQ docker image, such as version 3.8.

docker pull rabbitmq:3.8-management

Or, if you must use version 3.9, then you can create the .erlang.cookie file on your Docker system and use the -v or --volume option to mount the .erlang.cookie file on your Docker system to /var/lib/rabbitmq/.erlang.cookie in the container.

docker run --detach --volume /path/to/.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie rabbitmq:management