From ad2d6877e59094342414cdbac1d01e21b825446d Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Wed, 10 Apr 2024 19:06:45 -0400 Subject: [PATCH] Add dockerfile for building custom nginx container Add entrypoint that calls envsubst ahead of starting nginx --- nginx/Dockerfile | 10 ++++++++++ nginx/docker-entrypoint.sh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 nginx/Dockerfile create mode 100755 nginx/docker-entrypoint.sh diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..6ad0d66 --- /dev/null +++ b/nginx/Dockerfile @@ -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"] diff --git a/nginx/docker-entrypoint.sh b/nginx/docker-entrypoint.sh new file mode 100755 index 0000000..be6d293 --- /dev/null +++ b/nginx/docker-entrypoint.sh @@ -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;'