nginx-with-fancy-index/Dockerfile

54 lines
1.4 KiB
Docker
Raw Permalink Normal View History

2023-10-26 11:51:16 +01:00
# Stage 1: Build Nginx from source
FROM alpine:latest AS build
# Install build tools and dependencies
RUN apk update && apk upgrade
2023-10-26 12:01:24 +01:00
RUN apk add build-base wget pcre-dev zlib-dev git openssl-dev
2023-10-26 11:51:16 +01:00
# Download Nginx source code
WORKDIR /tmp
RUN wget http://nginx.org/download/nginx-1.25.3.tar.gz
RUN tar -zxvf nginx-*.tar.gz
2023-10-26 11:52:55 +01:00
RUN git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex
2023-10-26 11:51:16 +01:00
# Build Nginx from source
2023-10-26 11:59:53 +01:00
RUN cd nginx-* && ./configure --prefix=/usr/local/nginx \
2023-10-26 11:57:30 +01:00
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--with-http_ssl_module \
2023-10-26 12:03:44 +01:00
--add-module=../ngx-fancyindex \
&& make \
&& make install
2023-10-26 11:51:16 +01:00
# Stage 2: Create a minimal runtime image
FROM alpine:latest
2023-10-26 12:10:13 +01:00
# Install runtime dependencies
RUN apk update && apk upgrade
RUN apk add pcre pcre-dev
2023-10-26 12:19:30 +01:00
RUN mkdir /usr/local/nginx
2023-10-26 12:21:36 +01:00
RUN mkdir /usr/local/nginx/logs
2023-10-26 12:19:30 +01:00
RUN mkdir /var/log/nginx
2023-10-26 12:17:26 +01:00
RUN touch /usr/local/nginx/logs/error.log
RUN touch /usr/local/nginx/logs/access.log
2023-10-26 12:19:30 +01:00
RUN chmod -R 770 /usr/local/nginx
RUN chmod -R 770 /var/log/nginx
2023-10-26 12:17:26 +01:00
2023-10-26 11:51:16 +01:00
# Copy Nginx binary and configuration from the build stage
2023-10-26 11:55:02 +01:00
COPY --from=build /usr/local/sbin/nginx /usr/local/sbin/nginx
2023-10-26 11:51:16 +01:00
COPY --from=build /etc/nginx /etc/nginx
# Copy custom Nginx configuration
2023-10-26 11:52:04 +01:00
COPY ./nginx.conf /etc/nginx/nginx.conf
2023-10-26 11:51:16 +01:00
# Expose the default HTTP port
EXPOSE 80
# Start Nginx when the container runs
2023-10-26 11:59:53 +01:00
CMD ["/usr/local/sbin/nginx", "-g", "daemon off;"]