Renders config files from live Docker container metadata using Go templates, often paired with reverse proxies or log tools.
Overview
docker-gen watches Docker and fills text templates with structured container metadata, producing files such as nginx upstream blocks, log rotation rules, or fluentd snippets. Output can go to stdout for debugging or to paths your stack reloads when containers start and stop.
Typical deployment patterns run it on the host, bundled beside nginx or registrars in one image, or as a sidecar that shares volumes with nginx-proxy style setups so the Docker socket is not exposed on a public-facing service. Downloads supply binaries for host install, and a dedicated image exists for separate-container use.
Configuration can combine CLI flags with a multi-template config file executed in order. Templates use Go text/template plus sprig helpers and docker-gen-specific functions for grouping containers, sorting addresses and networks deterministically, and nginx-safe quoting. The emitted root exposes containers, networks, labels, and CurrentContainer for the docker-gen instance itself.
Documented examples include dynamic nginx reverse proxy generation similar to nginx-proxy, fluentd configuration, and etcd registration scripts. The project is maintained by ZeroSSL as upstream for nginx-related tooling.
Key features
- Go-template rendering from Docker events
- Multi-template ordered config files
- Sprig and custom template functions
- Stable sort for addresses and networks
- Host, bundled, or sidecar deployment
- nginx-proxy style reverse proxy configs
- Fluentd and logrotate generation examples
- Stdout mode for template debugging
Use cases
- Auto nginx upstreams for containers
- Centralized logging config per container
- Service registration from running containers
- Isolating Docker socket from public nginx
- Deterministic config regen on deploy