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 a RabbitMQ specific issue? e.g. I have to explicitly specify that a user must be persisted
FROM dockerfile/rabbitmq
# Define mount points.
VOLUME ["/data/log", "/data/mnesia"]
# Define working directory.
WORKDIR /data
RUN (rabbitmq-start &) && \
sleep 10 && \
rabbitmqctl add_user user1 password1 && \
rabbitmqctl set_user_tags user1 administrator && \
rabbitmqctl set_permissions -p / user1 ".*" ".*" ".*" && \
sleep 10 && \
rabbitmqctl stop && \
sleep 10
# Define default command.
CMD ["rabbitmq-start"]
# Expose ports.
EXPOSE 5672
EXPOSE 15672
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):
Runtime.sh (as entrypoint in Dockerfile):
I do something similar and it persists:
Are you sure the creation process occurs in the first place? The sleeps and subshells don't make it obvious.
For what is worth, something similar is done in this dockerfile, but I can't get it to persist either:
I know it's an old question, but struggled for hours with this problem today and finally solved it for me: The issue seems to be due to the default hostname changing at every new container with Docker, and RabbitMQ actually binds the configuration to the host name.
I set the NODENAME variable in /etc/rabbitmq/rabbitmq-env.conf before setting up the user:
and now it works.
Hope it can help.
EDIT:
Here is a working Dockerfile (copying a rabbitmq-env.conf file to the container):
My rabbitmq-env.conf file:
My rabbitmq-setup.sh: