Docker RabbitMQ persistency
Rabbitmq uses the hostname as part of the folder name in the mnesia directory. Maybe add a
--hostname some-rabbit
to your docker run?
I had the same issue and I found the answer here.
TL;DR
Didn't do too much digging on this, but it appears that the simplest way to do this is to change the hostname
as Pedro mentions above.
MORE INFO:
Using RABBITMQ_NODENAME
If you want to edit the RABBITMQ_NODENAME
variable via Docker, it looks like you need to add a hostname
as well since the Docker hostnames are generated as random hashes.
If you change the RABBITMQ_NODENAME
var to something static like my-rabbit
, RabbitMQ will throw something like an "nxdomain not found"
error because it's looking for something likemy-rabbit@<docker_hostname_hash>
. If you know the Docker hostname and can automate pulling it into your RABBITMQ_NODENAME
value like so, my-rabbit@<docker_hostname_hash>
I believe it would work.
UPDATE
I previously said,
If you know the Docker hostname and can automate pulling it into your
RABBITMQ_NODENAME
value like so,my-rabbit@<docker_hostname_hash>
I believe it would work.
This would not work as described precisely because the default docker host name is randomly generated at launch, if it is not assigned explicitly. The hurdle would actually be to make sure you use the EXACT SAME <docker_hostname_hash>
as your originating run so that the data directory gets picked up correctly. This would be a pain to implement dynamically/robustly. It would be easiest to use an explicit hostname as described below.
The alternative would be to set the hostname
to a value you choose -- say, app-messaging
-- AND ALSO set the RABBITMQ_NODENAME
var to something like rabbit@app-messaging
. This way you are controlling the full node name that will be used in the data directory.
Using Hostname
(Recommended)
That said, unless you have a reason NOT to change the hostname, changing the hostname alone is the simplest way to ensure that your data will be mounted to and from the same point every time.
I'm using the following Docker Compose file to successfully persist my setup between launches.
version: '3'
services:
rabbitmq:
hostname: 'mabbit'
image: "${ARTIFACTORY}/rabbitmq:3-management"
ports:
- "15672:15672"
- "5672:5672"
volumes:
- "./data:/var/lib/rabbitmq/mnesia/"
networks:
- rabbitmq
networks:
rabbitmq:
driver: bridge
This creates a data
directory next to my compose file and persists the RabbitMQ setup like so:
./data/
rabbit@mabbit/
rabbit@mabbit-plugins-expand/
[email protected]
rabbit@mabbit-feature_flags