Tengine makes dockerfile based on alpine image

1. Prepare the configuration file
Put default.conf and nginx.conf in the same directory as Dockerfile
!
vi default.conf

server {
    listen 80 default_server;
    server_name localhost;

    #charset koi8-r;
    #access_log /var/log/nginx/host.access-$year$month$day.log main;

    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    #include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    # deny all;
    #}
}

vi nginx.conf

user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
error_log "/var/log/nginx/error.log";
events {
        worker_connections 51200;
        use epoll;
}

http
{
        include mime.types;
        default_type application/octet-stream;
        map $http_x_forwarded_for $ClientRealIp {
                "" $remote_addr;
                ~^(?P<firstAddr>[0-9\.] + ),?.*$ $firstAddr;
        }
        log_format log_json '{"@timestamp":"$time_iso8601",'
                '"@version":"1",'
                        '"request_body": "$request_body",'
                        '"client":"$remote_addr",'
                        '"source_client":"$http_x_forwarded_for",'
                        '"client_realip":"$ClientRealIp",'
                        '"r":"$arg_r",'
                        '"url":"$uri",'
                        '"status": "$status",'
                        '"upstream_response_time": "$upstream_response_time",'
                        '"domain":"$host",'
                        '"host":"$server_addr",'
                        '"size":"$body_bytes_sent",'
                        '"responsetime":"$request_time",'
                        '"request_method": "$request_method", '
                        '"request": "$request", '
                        '"referer":"$http_referer",'
                        '"user_agent":"$http_user_agent",'
                        '}';
                access_log "/var/log/nginx/access.log" log_json;
                sendfile on;
                tcp_nopush on;
                tcp_nodelay on;
                server_tokens off;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                autoindex off;
                autoindex_exact_size off;
                autoindex_localtime off;
                keepalive_timeout 90;
                server_names_hash_bucket_size 128;
                client_header_buffer_size 256k;
                client_header_timeout 90s;
                client_body_timeout 90s;
                reset_timedout_connection on;
                send_timeout 90s;
                large_client_header_buffers 4 256k;
                client_max_body_size 80m;
                client_body_buffer_size 5120k;
                proxy_connect_timeout 90;
                proxy_read_timeout 90;
                proxy_send_timeout 90;
                proxy_buffer_size 512k;
                proxy_buffers 32 32k;
                proxy_busy_buffers_size 512k;
                proxy_temp_file_write_size 512k;
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                fastcgi_buffer_size 256k;
                fastcgi_buffers 4 256k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                gzip on;
                gzip_disable "msie6";
                gzip_proxied any;
                gzip_min_length 1k;
                gzip_buffers 4 16k;
                output_buffers 1 512k;
                postpone_output 1460;
                gzip_vary on;
                gzip_comp_level 3;
                gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml + rss text/javascript;

#################################################### ##########
  include /etc/nginx/conf.d/*.conf;
}

2. Build a mirror image
docker build -t tengine .

FROM alpine:3.12


ENV TENGINE_VERSION 2.3.3

# nginx: https://git.io/vSIyj

RUN rm -rf /var/cache/apk/* & amp; & amp; \
    rm -rf /tmp/*

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

ENV CONFIG "\
        --prefix=/etc/nginx \
        --sbin-path=/usr/sbin/nginx\
        --modules-path=/usr/lib/nginx/modules\
        --conf-path=/etc/nginx/nginx.conf\
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.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 \
        --user=nginx \
        --group=nginx \
        --with-http_ssl_module \
        --with-http_realip_module \
        --with-http_addition_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_random_index_module \
        --with-http_secure_link_module \
        --with-http_stub_status_module \
        --with-http_auth_request_module \
        --with-http_xslt_module=dynamic \
        --with-http_image_filter_module=dynamic \
        --with-http_geoip_module=dynamic \
        --with-threads \
        --with-stream \
        --with-stream_ssl_module \
        --with-stream_ssl_preread_module \
        --with-stream_realip_module \
        --with-stream_geoip_module=dynamic \
        --with-http_slice_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-compat \
        --with-file-aio \
        --with-http_v2_module \
        --add-module=modules/ngx_http_upstream_check_module \
        --add-module=modules/headers-more-nginx-module-0.33 \
        --add-module=modules/ngx_http_upstream_session_sticky_module \
        "
RUN addgroup -S nginx \
         & amp; & amp; adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
         & amp; & amp; addgroup -g 82 -S www-data & amp; & amp; adduser -u 82 -D -S -G www-data www-data \
         & amp; & amp; apk add --no-cache --virtual .build-deps \
                gcc \
                libc-dev\
                make \
                openssl-dev \
                pcre-dev \
                zlib-dev \
                linux-headers \
                curl \
                libxslt-dev \
                gd-dev \
                geoip-dev \
         & amp; & amp; wget "http://tengine.taobao.org/download/tengine-$TENGINE_VERSION.tar.gz" -O tengine.tar.gz \
         & amp; & amp; mkdir -p /usr/src \
         & amp; & amp; tar -zxC /usr/src -f tengine.tar.gz \
         & & rm tengine.tar.gz\
         & amp; & amp; cd /usr/src/tengine-$TENGINE_VERSION\
         & amp; & amp; wget "https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz" -O more.tar.gz \
         & amp; & amp; tar -zxC /usr/src/tengine-$TENGINE_VERSION/modules -f more.tar.gz \
         & amp; & amp; rm more.tar.gz\
         & amp; & amp; ls -l /usr/src/tengine-$TENGINE_VERSION/modules \
         & amp; & amp; ./configure $CONFIG --with-debug \
         & amp; & amp; make -j$(getconf _NPROCESSORS_ONLN)\
         & amp; & amp; mv objs/nginx objs/nginx-debug \
         & amp; & amp; mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
         & amp; & amp; mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
         & amp; & amp; mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so \
         & amp; & amp; mv objs/ngx_stream_geoip_module.so objs/ngx_stream_geoip_module-debug.so \
         & amp; & amp; ./configure $CONFIG \
         & amp; & amp; make -j$(getconf _NPROCESSORS_ONLN)\
         & amp; & amp; make install \
         & amp; & amp; rm -rf /etc/nginx/html/ \
         & amp; & amp; mkdir /etc/nginx/conf.d/ \
         & amp; & amp; mkdir -p /usr/share/nginx/html/ \
         & amp; & amp; install -m644 html/index.html /usr/share/nginx/html/ \
         & amp; & amp; install -m644 html/50x.html /usr/share/nginx/html/ \
         & amp; & amp; install -m755 objs/nginx-debug /usr/sbin/nginx-debug \
         & amp; & amp; install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
         & amp; & amp; install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
         & amp; & amp; install -m755 objs/ngx_http_geoip_module-debug.so /usr/lib/nginx/modules/ngx_http_geoip_module-debug.so \
         & amp; & amp; install -m755 objs/ngx_stream_geoip_module-debug.so /usr/lib/nginx/modules/ngx_stream_geoip_module-debug.so \
         & amp; & amp; ln -s ../../usr/lib/nginx/modules /etc/nginx/modules \
         & amp; & amp; strip /usr/sbin/nginx* \
         & amp; & amp; strip /usr/lib/nginx/modules/*.so \
         & amp; & amp; rm -rf /usr/src/tengine-$NGINX_VERSION \
        \
        # Bring in gettext so we can get `envsubst`, then throw
        # the rest away. To do this, we need to install `gettext`
        # then move `envsubst` out of the way so `gettext` can
        # be deleted completely, then move `envsubst` back.
         & amp; & amp; apk add --no-cache --virtual .gettext gettext \
         & amp; & amp; mv /usr/bin/envsubst /tmp/ \
        \
         & amp; & amp; runDeps="$( \
                scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
                        | tr ',' '\
' \
                        | sort -u \
                        | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
        )" \
         & amp; & amp; apk add --no-cache --virtual .nginx-rundeps $runDeps \
         & amp; & amp; apk del .build-deps \
         & amp; & amp; apk del .gettext\
         & amp; & amp; mv /tmp/envsubst /usr/local/bin/ \
        \
        # Bring in tzdata so users could set the timezones through the environment
        # variables
         & amp; & amp; apk add --no-cache tzdata \
        \
        # forward request and error logs to docker log collector
         & amp; & amp; ln -sf /dev/stdout /var/log/nginx/access.log \
         & amp; & amp; ln -sf /dev/stderr /var/log/nginx/error.log

COPY nginx.conf /etc/nginx/nginx.conf
COPY default.conf /etc/nginx/conf.d/

EXPOSE 80 443

STOP SIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]

3. Push the image to the warehouse

docker tag tengine:latest gem-acr-p-a01-registry.cn-shenzhen.cr.aliyuncs.com/devops/tengine-2.3.3:v1.0
docker push gem-acr-p-a01-registry.cn-shenzhen.cr.aliyuncs.com/devops/tengine-2.3.3:v1.0