pass external config file to docker container at runtime

Viewed 7965

I have a scala sbt application and have a default application.conf. I built a docker image to run this application via docker. How can I replace the default application.conf in the docker container at a run time?

2 Answers

I'd recommend instead of passing application.conf file with overrides, go with overrides based on environment variables, because of reasons like:

  • Mounting volume with configuration file might be tricky from deployment tools perspective;
  • Not all configurations management tools (for instance HashiCorp Consul) provide HOCON support, but managing environment variables is almost a standard. Especially if it contains secrets which needs to be protected;

So, you can do next: In your application conf set overrides via environment variable:

foo=default
foo={?FOO}

And run application docker container with specific override:

docker run ...
 -e foo=bar \
 ...

Please, see for more details:

Hope this helps!

docker run ... \
  --volume=[[YOUR-HOST-PATH]]/application.conf:[[YOUR-IMAGE-PATH]]/application.conf
  ...
Related