|
@@ -1,37 +1,19 @@
|
|
|
# 使用官方Nginx镜像作为基础
|
|
|
-FROM nginx:1.27.3 AS builder
|
|
|
+FROM nginx:1.27-alpine AS builder
|
|
|
|
|
|
-# 安装编译工具
|
|
|
-RUN apk add --no-cache \
|
|
|
- build-base \
|
|
|
- linux-headers \
|
|
|
- pcre-dev \
|
|
|
- zlib-dev
|
|
|
-
|
|
|
-# 下载Nginx源码(与基础镜像版本一致)
|
|
|
-RUN wget http://nginx.org/download/nginx-1.27.3.tar.gz && \
|
|
|
+RUN apk add --no-cache build-base linux-headers pcre-dev zlib-dev && \
|
|
|
+ wget http://nginx.org/download/nginx-1.27.3.tar.gz && \
|
|
|
tar -zxvf nginx-1.27.3.tar.gz && \
|
|
|
- rm nginx-1.27.3.tar.gz
|
|
|
-
|
|
|
-# 编译Nginx并启用所需模块
|
|
|
-WORKDIR /nginx-1.27.3
|
|
|
-RUN ./configure \
|
|
|
- --prefix=/etc/nginx \
|
|
|
- --sbin-path=/usr/sbin/nginx \
|
|
|
- --modules-path=/usr/lib/nginx/modules \
|
|
|
- --with-http_gzip_module \
|
|
|
- --with-http_gzip_static_module \
|
|
|
- --with-http_gunzip_module \
|
|
|
- --with-http_ssl_module && \
|
|
|
- make && \
|
|
|
- make install
|
|
|
+ cd nginx-1.27.3 && \
|
|
|
+ ./configure \
|
|
|
+ --prefix=/etc/nginx \
|
|
|
+ --with-http_gzip_module \
|
|
|
+ --with-http_gzip_static_module \
|
|
|
+ --with-http_gunzip_module && \
|
|
|
+ make && make install
|
|
|
|
|
|
-# 第二阶段:构建最终镜像
|
|
|
-FROM nginx:1.27.3
|
|
|
-
|
|
|
-# 从builder阶段复制编译好的二进制文件
|
|
|
+FROM nginx:1.27-alpine
|
|
|
COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx
|
|
|
-
|
|
|
# 验证模块
|
|
|
RUN nginx -V 2>&1 | grep -E 'gzip|gunzip'
|
|
|
|