Add dockerfile for building custom nginx container

Add entrypoint that calls envsubst ahead of starting nginx
This commit is contained in:
Ethan Paul 2024-04-10 19:06:45 -04:00
parent 0a84c8dd1b
commit ad2d6877e5
Signed by: enpaul
GPG Key ID: 9B6D99E4CFA31867
2 changed files with 26 additions and 0 deletions

10
nginx/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM docker.io/library/nginx:latest
ENV NEXTCLOUD_DOMAIN=example.com
ENV NEXTCLOUD_PHP_FPM_HOST=php-fpm-nextcloud:9000
ENV NEXTCLOUD_MAX_UPLOAD_SIZE=512M
ADD nginx.conf.template /nginx.conf.template
ADD docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["sh", "-c", "/docker-entrypoint.sh"]

16
nginx/docker-entrypoint.sh Executable file
View File

@ -0,0 +1,16 @@
#/usr/bin/env bash
# This implementation is adapted from the solution proposed here:
# https://stackoverflow.com/questions/21866477/nginx-use-environment-variables
# envsubst will take the input and replace all references to environment
# variables with their corresponding value. Because nginx uses the same
# '$' prefix for its internal variables, we should explicitly define the
# variables we want to replace rather than replacing all env vars.
envsubst '
$NEXTCLOUD_PHP_FPM_HOST
$NEXTCLOUD_DOMAIN
$NEXTCLOUD_MAX_UPLOAD_SIZE
' < /nginx.conf.template > /etc/nginx/nginx.conf
exec nginx -g 'daemon off;'