arrow_back
Back

Docker config files: templates, dockerize, and docker-gen

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

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.

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Docker Compose: services, networks, volumes, and compose.yml

arrow_forward