How to use docker-compose environment variables to populate config file

Viewed 5707

I'm new to docker-compose.
I'm trying to understand how can I pass environment variables via docker-compose to populate missing variables values in a config file during Dockerfile's build stage, so in the run phase, I will run the service- rabbitmq with its configuration filled with the env variables values.

In docker-compose yml file I have an env_file: and also environment:, question how can I pass them forward to populate the config file.

Any help, an idea would be greatly appreciated with a simple example of course.

Example rabbitmq config file (with env variable which need to be filled with its value for $SSL_PORT):

[{rabbit,
  [
    {loopback_users, []},
    {ssl_listeners, [$SSL_PORT]},
    {ssl_options, [{cacertfile,"/etc/rabbitmq/ca/cacert.pem"},
                   {certfile,"/etc/rabbitmq/server/cert.pem"},
                   {keyfile,"/etc/rabbitmq/server/key.pem"},
                   {verify,verify_none},
                   {fail_if_no_peer_cert,false}]}
  ]}
].
2 Answers
Related