nginx-with-fancy-index/Dockerfile

42 lines
1.1 KiB
Docker
Raw Normal View History

2023-10-26 10:51:16 +00:00
# Stage 1: Build Nginx from source
FROM alpine:latest AS build
# Install build tools and dependencies
RUN apk update && apk upgrade
RUN apk add build-base wget pcre-dev zlib-dev git
# 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 10:52:55 +00:00
RUN git clone https://github.com/aperezdc/ngx-fancyindex.git ngx-fancyindex
2023-10-26 10:51:16 +00:00
# Build Nginx from source
2023-10-26 10:57:30 +00:00
WORKDIR /tmp/nginx-*
2023-10-26 10:51:16 +00:00
RUN ./configure --prefix=/usr/local/nginx \
2023-10-26 10:57:30 +00:00
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_ssl_module \
--add-module=../ngx-fancyindex
2023-10-26 10:51:16 +00:00
RUN make
RUN make install
# Stage 2: Create a minimal runtime image
FROM alpine:latest
# Copy Nginx binary and configuration from the build stage
2023-10-26 10:55:02 +00:00
COPY --from=build /usr/local/sbin/nginx /usr/local/sbin/nginx
2023-10-26 10:51:16 +00:00
COPY --from=build /etc/nginx /etc/nginx
# Copy custom Nginx configuration
2023-10-26 10:52:04 +00:00
COPY ./nginx.conf /etc/nginx/nginx.conf
2023-10-26 10:51:16 +00:00
# Expose the default HTTP port
EXPOSE 80
# Start Nginx when the container runs
CMD ["/usr/local/sbin/nginx", "-g", "daemon off;"]