Skip to content

Instantly share code, notes, and snippets.

@isapir
Created December 20, 2022 16:23
Show Gist options
  • Save isapir/876736198f7128680b371b7d5ba44cdd to your computer and use it in GitHub Desktop.
Save isapir/876736198f7128680b371b7d5ba44cdd to your computer and use it in GitHub Desktop.
FROM ubuntu:22.04
ENV NGINX_VERSION=1.23.3
ENV NGINX_BIN=/usr/sbin/nginx
ENV NGINX_LOG=/var/log/nginx
ENV NGINX_CONF=/etc/nginx
ENV NGINX_RUN=/var/www
ENV NGINX_DIRS="${NGINX_BIN} ${NGINX_LOG} ${NGINX_CONF} ${NGINX_RUN}"
RUN apt-get update \
&& apt-get install -y curl vim build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgd-dev libxml2 libxml2-dev uuid-dev \
&& mkdir downloads \
&& cd downloads \
&& curl -s https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar xvz -C . \
&& cd nginx-${NGINX_VERSION} \
## do not treat warnings as errors
&& export CFLAGS="-Wno-error" \
## default webroot is at ${NGINX_RUN}/html
&& ./configure --prefix=${NGINX_RUN}/html --sbin-path=${NGINX_BIN} --conf-path=${NGINX_CONF}/nginx.conf \
--http-log-path=${NGINX_LOG}/access.log --error-log-path=${NGINX_LOG}/error.log \
--with-pcre --lock-path=${NGINX_LOG}/nginx.lock --pid-path=${NGINX_LOG}/nginx.pid --with-http_ssl_module \
--with-http_image_filter_module=dynamic --modules-path=/etc/nginx/modules --with-http_v2_module \
--with-stream=dynamic --with-http_addition_module --with-http_mp4_module \
&& make \
&& make install \
&& useradd --uid 1000 --user-group --shell /bin/bash nginx \
&& chown -R :1000 ${NGINX_DIRS} \
&& chmod -R g+srwX ${NGINX_DIRS} \
&& cd ${NGINX_CONF} \
&& rm -rf /downloads
USER nginx
### pass CMD as a string and not an array to utilize the ENV variable ${NGINX_BIN}
## but it disables CTRL+C so to stop the container either run it with `-it`
## or run `docker container exec nginx /usr/sbin/nginx -s stop`
CMD ${NGINX_BIN} -g 'daemon off;'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment