是時候更新一波操做系統版本與tengine版本啦!html
構建完成差很少38.4MB廢話很少說,直接上代碼!linux
# cat repositories
https://mirrors.ustc.edu.cn/alpine/v3.10/main
https://mirrors.ustc.edu.cn/alpine/v3.10/community
複製代碼
FROM alpine:3.10.1 as builder
LABEL maintainer laihh <laihh@wangsu.com>
#定義環境變量
ENV TENGINE_VERSION=2.3.1
#定義編譯參數
ENV CONFIG "\ --user=webrunner \ --group=webrunner \ --with-http_secure_link_module \ --with-http_image_filter_module \ --with-http_random_index_module \ --with-threads \ --with-http_ssl_module \ --with-http_sub_module \ --with-http_stub_status_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_realip_module \ --with-compat \ --with-file-aio \ --with-http_dav_module \ --with-http_degradation_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_xslt_module \ --with-http_auth_request_module \ --with-http_addition_module \ --with-http_v2_module \ --add-module=./modules/ngx_http_upstream_check_module \ --add-module=./modules/ngx_http_upstream_session_sticky_module \ --add-module=./modules/ngx_http_upstream_dynamic_module \ --add-module=./modules/ngx_http_upstream_consistent_hash_module \ --add-module=./modules/ngx_http_upstream_dyups_module \ --add-module=./modules/ngx_http_user_agent_module \ --add-module=./modules/ngx_http_proxy_connect_module \ --add-module=./modules/ngx_http_concat_module \ --add-module=./modules/ngx_http_footer_filter_module \ --add-module=./modules/ngx_http_sysguard_module \ --add-module=./modules/ngx_http_slice_module \ --add-module=../nginx_cookie_flag_module-1.1.0 \ --with-http_geoip_module=dynamic \ --prefix=/service/nginx/ \ --sbin-path=/usr/sbin/nginx \ --modules-path=/usr/lib64/nginx/modules \ --conf-path=/service/nginx/nginx.conf \ --http-log-path=/var/log/nginx/access.log \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx.pid \ --lock-path=/var/run/nginx.lock \ --http-client-body-temp-path=/var/cache/nginx/client_temp \ --http-proxy-temp-path=/var/cache/nginx/proxy_temp \ --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \ --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \ --http-scgi-temp-path=/var/cache/nginx/scgi_temp \ "
#替換apk源
COPY repositories /etc/apk/repositories
#編譯安裝
RUN \
mkdir -p /usr/src \
&& cd /usr/src \
&& apk add --no-cache --virtual .build-deps \
gcc \
geoip \
geoip-dev \
libxslt-dev \
libxml2-dev \
gd-dev \
libc-dev \
make \
openssl-dev \
pcre-dev \
zlib-dev \
linux-headers \
curl \
wget \
unzip \
g++ \
file \
perl \
pcre \
binutils \
&& wget https://github.com/AirisX/nginx_cookie_flag_module/archive/v1.1.0.tar.gz \
&& tar zxf v1.1.0.tar.gz \
&& curl "https://tengine.taobao.org/download/tengine-$TENGINE_VERSION.tar.gz" -o tengine.tar.gz \
&& tar zxf tengine.tar.gz \
&& cd tengine-$TENGINE_VERSION \
&& ./configure $CONFIG \
&& make \
&& make install \
&& rm -f /service/nginx/html/* /service/nginx/*.default \
&& strip /usr/sbin/nginx
#===== 多階段構建 ==========================
FROM alpine:3.10.1
ENV TENGINE_VERSION=2.3.1
ENV WWW_ROOT=/service/webindex/
ENV LANG="en_US.UTF-8"
ENV GLIBC_PKG_VERSION=2.24-r0
COPY --from=builder /usr/sbin/nginx /usr/sbin/nginx
COPY --from=builder /service/nginx /service/nginx
COPY --from=builder /usr/lib64/nginx /usr/lib64/nginx
RUN \
addgroup -S webrunner \
&& adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G webrunner webrunner \
&& mkdir -p ${WWW_ROOT}/demo/ /var/log/nginx /var/cache/nginx \
&& runDeps="$( \ scanelf --needed --nobanner /usr/sbin/nginx \ | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ | sort -u \ | xargs -r apk info --installed \ | sort -u \ )" \
&& apk add --no-cache --virtual .nginx-rundeps $runDeps gd libxslt geoip pcre\
&& apk add --no-cache gettext curl \
\
#將日誌標準輸出
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
\
#設置中國時區
&& apk add --no-cache tzdata \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
\
#安裝中文字體庫
&& mkdir -p /usr/src \
&& cd /usr/src \
&& curl -Lo /etc/apk/keys/sgerrand.rsa.pub "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_PKG_VERSION}/sgerrand.rsa.pub" \
&& curl -Lo glibc-${GLIBC_PKG_VERSION}.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_PKG_VERSION}/glibc-${GLIBC_PKG_VERSION}.apk" \
&& curl -Lo glibc-bin-${GLIBC_PKG_VERSION}.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_PKG_VERSION}/glibc-bin-${GLIBC_PKG_VERSION}.apk" \
&& curl -Lo glibc-i18n-${GLIBC_PKG_VERSION}.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_PKG_VERSION}/glibc-i18n-${GLIBC_PKG_VERSION}.apk" \
&& apk add glibc-${GLIBC_PKG_VERSION}.apk glibc-bin-${GLIBC_PKG_VERSION}.apk glibc-i18n-${GLIBC_PKG_VERSION}.apk \
&& /usr/glibc-compat/bin/localedef --force --inputfile POSIX --charmap UTF-8 "$LANG" || true \
&& echo "export LANG=$LANG" > /etc/profile.d/locale.sh \
\
#清理臨時文件
&& rm -fr /usr/src /var/cache/apk/*
CMD ["nginx", "-g", "daemon off;"]
複製代碼
# docker run -d --rm -p 80:80 --name tngtest tengine2.3.1:v1
4bd188b622290dae402b9a3106e31262cb04af741c1be19449b60f89382d2b23
# curl 127.0.0.1:80
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
Sorry for the inconvenience.<br/>
Please report this message and include the following information to us.<br/>
Thank you very much!</p>
<table>
<tr>
<td>URL:</td>
<td>http://127.0.0.1/</td>
</tr>
<tr>
<td>Server:</td>
<td>4bd188b62229</td>
</tr>
<tr>
<td>Date:</td>
<td>2019/08/18 00:58:14</td>
</tr>
</table>
<hr/>Powered by Tengine/2.3.1<hr><center>tengine</center>
</body>
</html>
複製代碼
看到tengine返回的頁面就大功告成了!nginx