(Similar to an unanswered post from yesterday but I've since zoomed in on the cause of my issue so re-posting here with less text and deleting yesterdays post)
With the nginx image one can pass global env variables. Documentation. On the link there's a section 'Using environment variables in nginx configuration (new in 1.19)'. When running this container the functionality described above about global variables does indeed work as expected.
If I exec into the running container I see a script at the root level of the directory system docker-entrypoint.sh. From research it sounds like the method nginx docker uses to pass global variables relies on this script being run when the container starts and that this is an automatic process.
The trouble is, my docker-compose has a command command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'". When I include this command and run, it breaks the functionality with global variables. From doing some searching, adding a command breaks any entry point scripts? It seems I can only make use of the global variable functionality if I don't add any commands to my docker-compose since it stops docker-entrypoint.sh from being run.
Is there a 'right' way around this?
Works - global variables are passed through to nginx:
version: "3.5"
networks:
collabora:
services:
nginx:
image: nginx
depends_on:
- certbot
- collabora
volumes:
- ./data/nginx/templates:/etc/nginx/templates
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
ports:
- "80:80"
- "443:443"
env_file: .env
networks:
- collabora
Does not work, global variables are not passed through and the default.conf template is all that I get:
version: "3.5"
networks:
collabora:
services:
nginx:
image: nginx
depends_on:
- certbot
- collabora
volumes:
- ./data/nginx/templates:/etc/nginx/templates
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
ports:
- "80:80"
- "443:443"
env_file: .env
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
networks:
- collabora