Templating config files at container start is common when the application does not read all settings from environment variables. For production apps, use a real template engine such as Jinja2 or Go’s text/template instead of fragile shell sed on regex-heavy configs.
dockerize
open_in_new jwilder/dockerize
renders config files from templates plus environment variables, then execs your application. Wrap your entrypoint in CMD or ENTRYPOINT:
dockerize -template /etc/app/config.tmpl:/etc/app/config.yml -- /usr/bin/myapp
docker-gen
open_in_new jwilder/docker-gen goes further: it reads container metadata (IP addresses, labels, env) and can run continuously, reacting to Docker events (create, start, destroy) to regenerate configs.
A well-known example is nginx-proxy, which watches VIRTUAL_HOST and builds upstream blocks for a load-balanced virtual host set.
Related topics
- Volumes — mount config from the host
- Setting up reverse proxy — nginx in front of containers
Andrew Dorokhov