wmnnd / nginx-certbot

Boilerplate configuration for nginx and certbot with docker-compose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using environment variables in nginx configuration not working because of renew certificates command

igi-1w3r53n opened this issue · comments

Related: nginxinc/docker-nginx#422 (comment)

I am using env variables in my docker-compose file and i was not able to get this setup running. It seems that nginx ignores its default commands and template compilation when the "command: "/bin/sh -c 'while :; do sleep 6h ..." renew certificates command is set in docker-compose file.

Maybe someone has a similar issue.

envsubst can be used to support environmental variables. see here:
https://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf

this could also be a feature to add to the repo

Yes, the ENTRYPOINT script (invoked here) appears responsible for this behavior. If the first argument to the container's CMD (as defined in command: in docker-compose.yml) is not nginx or nginx-debug, then the entrypoint script never looks for the 20-envsubst-on-templates.sh script. That is the case with the docker-compose.yml in this repo, because the command: starts with a while loop to reload Nginx every 6 hours.

I got it working by modifying the command: to run the envsubst script before starting Nginx:

command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & /docker-entrypoint.d/20-envsubst-on-templates.sh; nginx-debug -g \"daemon off;\"'"