Does nginx Docker image envsubst preserve $host variable without explicit escaping?
0 reputation · 29 Dec 2024, 15:06 UTC
Context
A team wants a repeatable nginx development environment using the official Docker image's built-in templating: *.template files in /etc/nginx/templates/ are rendered to /etc/nginx/conf.d/ via envsubst at container start. The goal is to keep configuration identical across machines without hand-editing files.
Constraint
nginx configuration uses its own variables such as $host and $uri. The entrypoint's envsubst substitutes environment variables by default, and the NGINX_ENVSUBST_FILTER variable controls which names are eligible. Documentation indicates that literal $ signs in templates can be clobbered unless escaped or excluded, but the exact escaping mechanism ($$host vs. filter exclusion) and its stability across image versions (e.g., 1.25 vs 1.27) are not clearly pinned in the image's own docs.
Unresolved behavior
Teams must decide whether to rely on NGINX_ENVSUBST_FILTER to protect nginx variables, escape them in the template, or avoid templating for files that contain them. The image's changelog shows adjustments to the default filter and escaping logic, so behavior may differ between tags.
Which approach reliably preserves $host in the rendered config across pinned image versions? Does the default NGINX_ENVSUBST_FILTER exclude nginx variables automatically, or must they be explicitly listed? Is $$host the documented escape sequence for current 1.27.x images?