2019-10-16 23:44:47 -06:00
FROM nginx:mainline-alpine
2019-11-11 00:04:15 -07:00
# default username and uid for nginx user
ARG UID = 8001
# create nginx user
2021-01-07 07:03:57 -07:00
RUN addgroup --gid ${ UID } www-docker \
2019-11-11 00:04:15 -07:00
&& adduser \
--disabled-password \
--gecos 'nginx docker system user' \
--home '/usr/share/nginx/html' \
2021-01-07 07:03:57 -07:00
--ingroup www-docker \
2019-11-11 00:04:15 -07:00
--no-create-home \
--uid ${ UID } \
2021-01-07 07:03:57 -07:00
www-docker
2019-11-11 00:04:15 -07:00
2021-01-07 06:59:53 -07:00
# add nano, fun error pages & LetsEncrypt challenge directory outside webroot
RUN apk --no-cache add nano \
2019-10-17 23:27:50 -06:00
&& cd /usr/share/nginx \
&& rm -rf html/* \
2021-01-07 06:59:53 -07:00
&& wget -O /tmp/errorpages.tar.gz https://git.asifbacchus.app/asif/fun-errorpages/archive/v1.0.tar.gz \
&& tar -xzf /tmp/errorpages.tar.gz -C /tmp \
&& mv /tmp/fun-errorpages/errorpages ./ \
&& rm -rf /tmp/*
2019-10-17 00:13:42 -06:00
2021-01-05 17:35:03 -07:00
# health check
HEALTHCHECK --interval=60s --timeout=5s --start-period= 30s --retries= 3 \
2021-01-05 18:24:58 -07:00
CMD curl --fail http://127.0.0.1:9000/nginx_status || exit 1
2021-01-05 17:35:03 -07:00
2019-10-16 23:44:47 -06:00
# standardized labels
2021-01-05 18:01:53 -07:00
LABEL author = "Asif Bacchus <asif@bacchus.cloud>"
2019-10-16 23:44:47 -06:00
LABEL maintainer = "Asif Bacchus <asif@bacchus.cloud>"
2021-01-05 18:01:53 -07:00
LABEL org.opencontainers.image.author= "Asif Bacchus <asif@bacchus.cloud>"
LABEL org.opencontainers.image.url= "https://git.asifbacchus.app/ab-docker/ab-nginx"
LABEL org.opencontainers.image.documentation= "https://git.asifbacchus.app/ab-docker/ab-nginx/wiki"
LABEL org.opencontainers.image.source= "https://git.asifbacchus.app/ab-docker/ab-nginx.git"
LABEL org.opencontainers.image.vendor= "NGINX"
LABEL org.opencontainers.image.title= "ab-nginx"
LABEL org.opencontainers.image.description= "NGINX-mainline-alpine with more logical file location layout and automatic SSL set up if certificates are provided."
2019-10-16 23:44:47 -06:00
# copy configuration files
2021-01-07 06:59:53 -07:00
COPY nanorc /etc/nanorc
2019-10-16 23:44:47 -06:00
COPY entrypoint.sh /entrypoint.sh
COPY config /etc/nginx/
COPY sites /etc/nginx/sites/
2019-10-17 01:01:20 -06:00
COPY webroot /usr/share/nginx/html/
2019-10-16 23:44:47 -06:00
# expose ports
EXPOSE 80 443
2021-01-07 07:05:20 -07:00
# clean-up permissions and run as www-docker user
2021-01-07 07:14:01 -07:00
RUN chown -R www-docker:www-docker /usr/share/nginx/html \
2019-11-09 20:01:29 -07:00
&& find /usr/share/nginx/html -type d -exec chmod 775 { } \; \
&& find /usr/share/nginx/html -type f -exec chmod 664 { } \; \
2021-01-07 07:14:01 -07:00
&& chown -R www-docker:www-docker /etc/nginx \
2019-11-09 20:01:29 -07:00
&& find /etc/nginx -type d -exec chmod 770 { } \; \
&& find /etc/nginx -type f -exec chmod 660 { } \;
2021-01-07 07:03:57 -07:00
USER www-docker
2019-11-09 20:01:29 -07:00
2019-10-16 23:44:47 -06:00
# default environment variables
2019-10-18 01:32:48 -06:00
ENV TZ = Etc/UTC
2019-10-17 00:13:51 -06:00
ENV SERVER_NAMES = "_"
2019-10-17 21:26:18 -06:00
ENV HTTP_PORT = 80
ENV HTTPS_PORT = 443
2019-10-18 01:53:20 -06:00
ENV ACCESS_LOG = OFF
2019-10-17 00:13:51 -06:00
ENV HSTS = FALSE
ENV TLS13_ONLY = FALSE
2019-10-16 23:44:47 -06:00
# entrypoint script
ENTRYPOINT [ "/entrypoint.sh" ]
# run NGINX by default
CMD [ "nginx" , "-g" , "daemon off;" ]
2020-03-10 23:20:54 -06:00
# add build date and version labels
2019-10-16 23:44:47 -06:00
ARG BUILD_DATE
2021-01-05 18:01:53 -07:00
LABEL org.opencontainers.image.version= "1.19.6"
2021-01-07 07:03:57 -07:00
LABEL app.asifbacchus.docker.internalVersion= "3.1"
2021-01-05 18:01:53 -07:00
LABEL org.opencontainers.image.created= ${ BUILD_DATE }
#EOF