Docker Community Forums

Share and learn in the Docker community.

Where to store configuration


(Negw) #1

Hello, I’m dockerizing a couple of RoR applications, and I’m a little puzzled about where to store configuration.
Target deployment will be AWS ECS that actually supports docker-compose, I’m then building the docker-compose.yml which will contain literally a truckload of environment variable that will get used when building the containers.
My “problem” is that I have multiple environments (test, development, staging, production) and these variables are actually hardcoded into the docker-compose, which I believe is a very bad practice as per https://12factor.net/config.
I’ve been suggested on slack to have a script populate docker-compose but it doesn’t look like a very good option, I’d need to host this script on git with the source code right?
What is people doing about this? Ansible? Looks a little overwhelming when used for configuration only, no?
Thanks for all the help, ~ngw


(David Maze) #2

I tend to treat the docker-compose.yml as configuration, not code, and it’s a reasonable place to set big piles of environment variables. If you’re using something like the ECS native API (or Kubernetes, or Nomad, or …) there’s a different syntax for setting environment variables; but this is the configuration “at the deployment layer” and this is pretty much the right place to do it. There are also reasonable differences between environments (external database hostnames, replica counts, $RACK_ENV, …) and the docker-compose.yml file(s) can encapsulate these well.

The important details here are to use the same image in all environment; to actually have your code in the image (don’t bind-mount application code into a container, that misses the point); and to not have host names or credentials hard-coded into your application (the .rb files, that is).