FROM centos:7 as build ADD nginx-1.19.6.tar.gz /usr/local/src # change dir to /usr/local/src/nginx-1.19.6 WORKDIR /usr/local/src/nginx-1.19.6 # running required command RUN yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel libxslt-devel gd gd-devel GeoIP GeoIP-devel pcre pcre-devel && useradd -M -s /sbin/nologin nginx && ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module &> /dev/null && make &> /dev/null &> /dev/null && make install &> /dev/null && rm -fr /usr/local/src/nginx-* FROM centos:7 COPY --from=build /usr/local/nginx /usr/local/nginx EXPOSE 80 443 VOLUME ["/usr/local/nginx/html"] CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
分阶段构造docker镜像,可显著降低镜像大小