Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker rabbitmq hostname issue

I am build an image using Dockerfile, and I would like to add users to RabbitMQ right after installation. The problem is that during build hostname of the docker container is different from when I run the resultant image. RabbitMQ loses that user; because of changed hostname it uses another DB.

I connot change /etc/hosts and /etc/hostname files from inside a container, and looks that RabbitMQ is not picking my changes to RABBITMQ_NODENAME and HOSTNAME variables.

The only thing that I found working is running this before starting RabbitMQ broker:

echo "NODENAME=rabbit@localhost" >> /etc/rabbitmq/rabbitmq.conf.d/ewos.conf

But then I will have to run docker image with changed hostname all the time.

docker run -h="localhost" image

Any ideas on what can be done? Maybe the solution is to add users to RabbitMQ not on build but on image run?

like image 207
yun_man_ger Avatar asked Sep 25 '13 04:09

yun_man_ger


2 Answers

Just here is example how to configure from Dockerfile properly:

ENV HOSTNAME localhost

RUN /etc/init.d/rabbitmq-server start ; rabbitmqctl add_vhost /test; /etc/init.d/rabbitmq-server stop

This is remember your config.

like image 62
Rubycut Avatar answered Sep 22 '22 06:09

Rubycut


Yes, I would suggest to add users when the container runs for the first time.

Instead of starting RabbitMQ directly, you can run a wrapper script that will take care of all the setup, and then start RabbitMQ. If the last step of the wrapper script is a process start, remember that you can use exec so that the new process replaces the script itself.

like image 38
jpetazzo Avatar answered Sep 23 '22 06:09

jpetazzo