3

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_policycommand 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?

Mehran
  • 15,593
  • 27
  • 122
  • 221

2 Answers2

2

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
rabbit@bf97c82990aa.pid

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.

Options

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?

Matt
  • 68,711
  • 7
  • 155
  • 158
  • Could you please elaborate on how and where to put the `ExecStartPost` entry? I know it's supposed to be in the service unit configuration file, but I'm it's my first time doing so and some pointers would be great. Thanks. – Mehran Feb 15 '16 at 14:19
  • It seems like the official `rabbitmq` image does not run it as a service so I think your solution to use `ExecStartPost` won't work! – Mehran Feb 15 '16 at 19:15
  • The default [`Type`](https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=) for systemd is a simple, non forking process. – Matt Feb 15 '16 at 23:55
  • The problem in this case is that RabbitMQ is not run as a daemon / service at all! Just a simple foreground program. – Mehran Feb 20 '16 at 20:21
  • That's not a problem, systemd can do all the daemon management for a foreground process. `Type=simple` is the default for a systemd managed process run with `ExecStart`. It can also manage processes that can daemonise them selves, which you configure with `Type=forking` – Matt Feb 23 '16 at 04:28
2

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"
Andrey
  • 346
  • 1
  • 7