ARG NGINX_TMP_INSTALL_DIR=/tmp/nginx-rtmp FROM alpine:latest as builder ARG NGINX_TMP_INSTALL_DIR ENV NGINX_VERSION=1.18.0 ENV NGINX_RTMP_MODULE_COMMIT=23ec4ce2d769830124abf3be1353dd9b105ab09c # Install dependencies RUN apk --update-cache add build-base openssl-dev pcre-dev zlib-dev # Download and extract nginx source RUN mkdir -p /tmp/build/nginx && \ cd /tmp/build/nginx && \ wget -O nginx.tar.gz https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ tar -zxf nginx.tar.gz # Download and extract RTMP module source RUN mkdir -p /tmp/build/nginx-rtmp-module && \ cd /tmp/build/nginx-rtmp-module && \ wget -O module.zip https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/${NGINX_RTMP_MODULE_COMMIT}.zip && \ unzip module.zip # Build and install nginx in a specific directory in order to isolate it for later copy RUN cd /tmp/build/nginx/nginx-${NGINX_VERSION} && \ ./configure \ --sbin-path=/usr/local/sbin/nginx \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/tmp/nginx-client-body \ --with-http_ssl_module \ --with-threads \ --add-module=/tmp/build/nginx-rtmp-module/nginx-rtmp-module-${NGINX_RTMP_MODULE_COMMIT} && \ make -j$(nproc) && \ make DESTDIR=${NGINX_TMP_INSTALL_DIR} install # Replace default with custom config COPY nginx.conf ${NGINX_TMP_INSTALL_DIR}/usr/local/nginx/conf/nginx.conf FROM alpine:latest ARG NGINX_TMP_INSTALL_DIR RUN apk --no-cache add libssl1.1 pcre zlib # Copy installed nginx from previous stage COPY --from=builder ${NGINX_TMP_INSTALL_DIR} / CMD ["nginx", "-g", "daemon off;"]