Reputation: 16841
I'm trying to make a Dockerfile based on the RabbitMQ repository with a customized policy set. The problem is that I can't useCMD
or ENTRYPOINT
since it will override the base Dockerfile's and then I have to come up with my own and I don't want to go down that path. Let alone the fact if I don't use RUN
, it will be a part of run time commands and I want this to be included in the image, not just the container.
Other thing I can do is to use RUN
command but the problem with that is the RabbitMQ server is not running at build time and also there's no --offline
flag for the set_policy
command of rabbitmqctl
program.
When I use docker's RUN
command to set the policy, here's the error I face:
Error: unable to connect to node rabbit@e06f5a03fe1f: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@e06f5a03fe1f]
rabbit@e06f5a03fe1f:
* connected to epmd (port 4369) on e06f5a03fe1f
* epmd reports: node 'rabbit' not running at all
no other nodes on e06f5a03fe1f
* suggestion: start the node
current node details:
- node name: 'rabbitmq-cli-136@e06f5a03fe1f'
- home dir: /var/lib/rabbitmq
- cookie hash: /Rw7u05NmU/ZMNV+F856Fg==
So is there any way I can set a policy for the RabbitMQ without writing my own version of CMD
and/or ENTRYPOINT
?
Upvotes: 3
Views: 1986
Reputation: 356
You can configure the policy as described here.
Docker compose:
rabbitmq:
image: rabbitmq:3.7.8-management
container_name: rabbitmq
volumes:
- ~/rabbitmq/data:/var/lib/rabbitmq:rw
- ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
- ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json
ports:
- "5672:5672"
- "15672:15672"
Upvotes: 2
Reputation: 74680
You're in a slightly tricky situation with RabbitMQ as it's mnesia data path is based on the host name of the container.
root@bf97c82990aa:/# ls -1 /var/lib/rabbitmq/mnesia
rabbit@bf97c82990aa
rabbit@bf97c82990aa-plugins-expand
[email protected]
For other image builds you could seed the data files, or write a script that RUN
calls to launch the application or database and configure it. With RabbitMQ, the container host name will change between image build and runtime so the image's config won't be picked up.
I think you are stuck with doing the config on container creation or at startup time.
Creating a wrapper CMD
script to do the policy after startup is a bit complex as /usr/lib/rabbitmq/bin/rabbitmq-server
runs rabbit in the foreground, which means you don't have access to an "after startup" point. Docker doesn't really do background processes so rabbitmq-server -detached
isn't much help.
If you were to use something like Ansible, Chef or Puppet to setup the containers. Configure a fixed hostname for the containers startup. Then start it up and configure the policy as the next step. This only needs to be done once, as long as the hostname is fixed and you are not using the --rm
flag.
At runtime, systemd could complete the config to a service with ExecStartPost
. I'm sure most service managers will have the same feature. I guess you could end up dropping messages, or at least causing errors at every start up if anything came in before configuration was finished?
Upvotes: 2