RabbitMQ in Docker - user creation not persisted
rabbitmq add user
docker rabbitmq cluster
etc/rabbitmq/rabbitmq config not found
rabbitmq add user dockerfile
rabbitmq docker enable plugin
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
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:
# make the node name static RUN echo 'NODENAME=rabbit@localhost' > /etc/rabbitmq/rabbitmq-env.conf
and now it works.
Hope it can help.
Here is a working Dockerfile (copying a rabbitmq-env.conf file to the container):
FROM ubuntu:latest RUN groupadd -r rabbitmq && useradd -r -d /var/lib/rabbitmq -m -g rabbitmq rabbitmq # add rabbitmq repo RUN apt-get update && \ apt-get install wget --assume-yes && \ wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc && \ sudo apt-key add rabbitmq-signing-key-public.asc && \ sed -i -e '1ideb http://www.rabbitmq.com/debian/ testing main\' /etc/apt/sources.list && \ apt-get update && \ apt-get install rabbitmq-server --assume-yes # Enable plugins RUN rabbitmq-plugins enable rabbitmq_management && \ rabbitmq-plugins enable rabbitmq_web_stomp && \ rabbitmq-plugins enable rabbitmq_mqtt # expose ports # Management EXPOSE 15672 # Web-STOMP plugin EXPOSE 15674 # MQTT: EXPOSE 1883 # configure RabbitMQ COPY ["rabbitmq-env.conf", "/etc/rabbitmq/rabbitmq-env.conf"] RUN chmod 755 /etc/rabbitmq/rabbitmq-env.conf # Create users for the apps COPY ["rabbitmq-setup.sh", "/tmp/rabbitmq/rabbitmq-setup.sh"] RUN mkdir /var/run/rabbitmq && \ chmod -R 755 /var/run/rabbitmq && \ chown -R rabbitmq:rabbitmq /var/run/rabbitmq && \ service rabbitmq-server start && \ sh /tmp/rabbitmq/rabbitmq-setup.sh && \ rm /tmp/rabbitmq/rabbitmq-setup.sh && \ service rabbitmq-server stop # start rabbitmq USER rabbitmq CMD ["rabbitmq-server", "start"]
My rabbitmq-env.conf file:
rabbitmqctl add_vhost myvhost && rabbitmqctl add_user myuser mypasswd && rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*" && rabbitmqctl set_user_tags myuser administrator
Won't persist data · Issue #106 · docker-library/rabbitmq · GitHub, I am using this container like following docker run \ --restart always \ --name rabbitmq1 \ -p I am trying to persist the data (like exchanges, users, vhost, etc. kind of glaring warning / or not even start the container without setting the hostname. Here I expect to see the queue I already created, but I don't. From: Tianon Gravi <email@example.com> Sent: Wednesday, April 11, 2018 12:34 PM To: docker-library/rabbitmq <firstname.lastname@example.org> Cc: June, Ben <email@example.com>; Comment <firstname.lastname@example.org> Subject: Re: [docker-library/rabbitmq] Won't persist data Using "docker commit" won't save the contents of the volumes
I do something similar and it persists:
RUN service rabbitmq-server start ; \ rabbitmqctl add_vhost /sensu ; \ rabbitmqctl add_user sensu sensu ; \ rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*" ; \ service rabbitmq-server stop
Are you sure the creation process occurs in the first place? The sleeps and subshells don't make it obvious.
bitnami/rabbitmq, However, because they run as a non-root user, privileged tasks are typically off-limits. To avoid this loss of data, you should mount a volume that will persist even In this example, we will create a RabbitMQ client instance that will connect to I'm having an issue with the RabbitMQ module. When I add a vhost and a user via the RabbitMQ module, the vhost nor user persist after a reboot. Prior to the reboot I can see the user exists via rabbitmqctl list_users and rabbitmqctl list
For what is worth, something similar is done in this dockerfile, but I can't get it to persist either:
RUN /usr/sbin/rabbitmq-server -detached && \ sleep 5 && \ rabbitmqctl add_user bunnyuser my_pass1 && \ rabbitmqctl add_user bunny-admin my_pass2 && \ rabbitmqctl set_user_tags bunny-admin administrator && \ rabbitmqctl set_permissions -p / bunnyuser ".*" ".*" ".*"
Clients Libraries and Developer Tools, In addition, the RabbitMQ community has created numerous clients, adaptors and tools that Provisioning (Chef, Puppet, Docker, etc) that fans out messages to every queue in the broker no matter what the bindings or vhosts. QDB: Persistent Message Queues with Replay: queue backup and replay over AMQP 0-9-1. Setting permissions for user "user1" in vhost "/" docker exec -it rabbitmq rabbitmqctl list_users Listing users user1  guest [administrator] Now when I stop, remove and start container again. docker-compose stop docker rm $(docker ps -aq --filter "status=exited") docker-compose up -d rabbitmq docker exec -it rabbitmq rabbitmqctl list
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
Configuration, It is possible to print effective configuration (user provided values merged into defaults) RabbitMQ packages or nodes will not create any configuration files. This value only takes effect when messages are persisted to the message store. To configure kernel limits for Docker contains, use the "default-ulimits" key in Create a durable queue by specifying durable as true during creation of your queue. You can check in the RabbitMQ Management UI, in the queue tab that the queue is marked with a "D" to ensure that the queue is durable. Set message delivery mode to persistent Making a queue durable is not the same as making the messages on it persistent.
Backup and Restore, Users, vhosts, queues, exchanges, bindings, runtime parameters all fall into this is sufficient for creating a broker with an identical set of definitions (e.g. users, Message data for unknown vhosts and queues will not be loaded and can be @sylogex that usually means you've also supplied environment variables to the rabbitmq image which are requesting that we update the configuration (which is bind-mounted as read-only, so that can't work)
Persistence Configuration, Persistent messages will be written to disk as soon as they reach the queue, in the message store index and thus do not have a memory cost when paged out. taken into account, then the disk-accessing queues will share the file handles Persistence Configuration Overview. The RabbitMQ persistence layer is intended to provide reasonably good throughput in the majority of situations without configuration. However, some configuration is sometimes useful. This guide covers a few configurable values that affect throughput, latency and I/O characteristics of a node.
Lazy Queues, Note that persistent messages can be written to disk as they enter the broker and of RabbitMQ improved the paging algorithm, the situation is still not ideal for use cases It is important to overprovision disk space to account for such peaks. Queues Introduction. This guide provides an overview of queues in RabbitMQ. Since many features in a messaging system are related to queues, it is not meant to be an exhaustive guide but rather an overview that provides links to other guides.
- Did you find a solution to this issue? I am looking for the same thing.
- No, I never did.
- Does the answer with 16 upvotes perhaps solve your problem?
- Could you share your Dockerfile? I am looking to find a solution for the same problem. My users do not get persisted.
- @Marco: sure, see my edited answer ;) You'll probably have to expose the ports you need and enable/disable plugins.
- Note that you need to be careful if you generate your files with Windows. Make sure that all files only use LF line endings. I just needed 1+ hour to figure out that rabbitmq was looking for a hostname called "localhost\R" (rabbitmq-env.conf).
- Yes, I tried building an image using your code, and inspect the list of user using
docker exec -ti rmq rabbitmqctl list_usersand couldn't find the newly created user. Am I missing something?
- I'm not a rabbitmq expert at all, sorry. I'd try to search the rabbitmq logs for hints.
- Hi. Do you find correct Dockerfile which allow to store multiple accoundt and permissions?