I\'ve got a problem where the user user1
is not persisted in the container that I have created using the following Dockerfile. What is the reason for this? Is this
Because many people are still having this problem (including me), what I did was:
At building, copy the RabbitMQ database_dir at /var/lib/rabbitmq/mnesia/rabbit\@$(hostname) to /root (everything in /root stays persisted) after configuring all users.
At runtime, copy the database dir back from /root to /var/lib/rabbitmq/mnesia.
Only disadvantages: changes made to the database in RabbitMQ will be reset at runtime. I found no other way to do this with docker-compose however.
Configure.sh (as RUN command in Dockerfile):
echo "NODENAME=rabbit@message-bus" > /etc/rabbitmq/rabbitmq-env.conf
echo "127.0.0.1 message-bus" >> /etc/hosts #prevents error that 'message-bus' node doesnt exist (this doesnt persist in /etc/hosts)
rabbitmqctl add user ... #etc
rabbitmqctl stop
mkdir /root/rabbitmq_database
cp -R /var/lib/rabbitmq/mnesia/rabbit\@message-bus/* /root/rabbitmq_database
Runtime.sh (as entrypoint in Dockerfile):
#copy database back from /root
mkdir -p /var/lib/rabbitmq/mnesia/rabbit\@message-bus
cp -R /root/rabbitmq_database/* /var/lib/rabbitmq/mnesia/rabbit\@message-bus
rabbitmq-server