{"id":837,"date":"2026-02-06T04:20:12","date_gmt":"2026-02-06T04:20:12","guid":{"rendered":"https:\/\/opshub.com.cn\/?p=837"},"modified":"2026-02-06T04:22:10","modified_gmt":"2026-02-06T04:22:10","slug":"docker%e5%a4%9a%e9%98%b6%e6%ae%b5%e6%9e%84%e5%bb%baopenresty","status":"publish","type":"post","link":"https:\/\/opshub.com.cn\/?p=837","title":{"rendered":"docker\u591a\u9636\u6bb5\u6784\u5efaopenresty"},"content":{"rendered":"\n<p><strong>\u591a\u9636\u6bb5\u6784\u5efa OpenResty<\/strong>\u7684 Dockerfile\uff0c\u57fa\u4e8e debian:stable-slim\uff0c\u6838\u5fc3\u505a\u4e86 OpenResty \u6e90\u7801\u7f16\u8bd1\uff08\u589e\u5927 nginx \u9519\u8bef\u65e5\u5fd7\u6700\u5927\u5b57\u7b26\u4e32\u957f\u5ea6\uff09\u3001\u7cbe\u7b80\u6784\u5efa\u4ea7\u7269\u3001\u6700\u7ec8\u751f\u6210\u8f7b\u91cf\u8fd0\u884c\u955c\u50cf\u7684\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM debian:stable-slim AS builder\nWORKDIR \/app\nADD .\/openresty-1.27.1.2.tar.gz \/app\nRUN \/bin\/rm -f \/etc\/apt\/sources.list.d\/* &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian\/ bookworm main contrib non-free non-free-firmware\" >\/etc\/apt\/sources.list &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian\/ bookworm-updates main contrib non-free non-free-firmware\" >>\/etc\/apt\/sources.list &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian-security bookworm-security\/updates main contrib non-free non-free-firmware\" >> \/etc\/apt\/sources.list &amp;&amp; \\\napt-get update &amp;&amp; \\\napt-get -y install gcc make libpcre3-dev libssl-dev zlib1g-dev perl &amp;&amp; \\\ncd openresty-1.27.1.2 &amp;&amp; \\\nsed -i '\/^#define NGX_MAX_ERROR_STR\/s\/4096\/10240000\/g' .\/bundle\/nginx-1.27.1\/src\/core\/ngx_log.h &amp;&amp; \\\n.\/configure --prefix=\/usr\/local\/openresty &amp;&amp; \\\ngmake &amp;&amp; \\\ngmake install &amp;&amp; \\\nstrip \/usr\/local\/openresty\/nginx\/sbin\/nginx\n\nFROM debian:stable-slim\nRUN \/bin\/rm -f \/etc\/apt\/sources.list.d\/* &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian\/ bookworm main contrib non-free non-free-firmware\" >\/etc\/apt\/sources.list &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian\/ bookworm-updates main contrib non-free non-free-firmware\" >>\/etc\/apt\/sources.list &amp;&amp; \\\necho \"deb http:\/\/mirrors.nju.edu.cn\/debian-security bookworm-security\/updates main contrib non-free non-free-firmware\" >> \/etc\/apt\/sources.list &amp;&amp; \\\napt-get update &amp;&amp; \\\napt-get -y install libpcre3-dev libssl-dev zlib1g-dev &amp;&amp; \\\napt clean &amp;&amp; \\\n\/bin\/rm -rf \/var\/lib\/apt\/lists\/*\nCOPY  --from=builder \/usr\/local\/openresty\/ \/usr\/local\/openresty\/\nENV PATH \"\/usr\/local\/openresty\/bin:\/usr\/local\/openresty\/nginx\/sbin:$PATH\"\nENTRYPOINT &#91;\"nginx\", \"-g\", \"daemon off;\"]\n<\/code><\/pre>\n\n\n\n<p><strong>\u57fa\u4e8e Alpine 3.21.3 \u7684 OpenResty \u591a\u9636\u6bb5\u6784\u5efa Dockerfile<\/strong>\uff0c\u76f8\u6bd4\u4e4b\u524d\u7684 Debian \u7248\u672c\uff0cAlpine \u672c\u8eab\u662f\u8f7b\u91cf Linux \u53d1\u884c\u7248\uff0c\u6700\u7ec8\u955c\u50cf\u4f53\u79ef\u4f1a\u66f4\u5c0f\uff0c\u8fd8\u505a\u4e86\u65f6\u533a\u914d\u7f6e\u3001\u5f00\u542f\u66f4\u591a Nginx \u5b9e\u7528\u6a21\u5757\u3001\u76f4\u63a5\u5728\u7ebf\u4e0b\u8f7d\u6e90\u7801\u7b49\u4f18\u5316<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># stage 1: \u6784\u5efa\u9636\u6bb5\nFROM alpine:3.21.3 AS builder\n \nARG OPENRESTY_VERSION=1.27.1.2\n \n# \u66ff\u6362\u4e3a\u963f\u91cc\u4e91\u6e90\u5e76\u5b89\u88c5\u6784\u5efa\u4f9d\u8d56\nRUN sed -i 's|https:\/\/dl-cdn.alpinelinux.org\/alpine|https:\/\/mirrors.aliyun.com\/alpine|g' \/etc\/apk\/repositories &amp;&amp; \\\n    apk add --no-cache \\\n    build-base \\\n    pcre-dev \\\n    openssl-dev \\\n    zlib-dev \\\n    perl \\\n    linux-headers\n \n# \u62f7\u8d1d\u5e76\u89e3\u538b OpenResty \u6e90\u7801\nWORKDIR \/tmp\nRUN wget https:\/\/openresty.org\/download\/openresty-${OPENRESTY_VERSION}.tar.gz &amp;&amp; \\\n    tar zxpf openresty-${OPENRESTY_VERSION}.tar.gz &amp;&amp; \\\n    sed -i '\/^#define NGX_MAX_ERROR_STR\/s\/4096\/2048000\/g' openresty-${OPENRESTY_VERSION}\/bundle\/nginx-1.27.1\/src\/core\/ngx_log.h\n \n# \u7f16\u8bd1\u5b89\u88c5 OpenResty\nWORKDIR \/tmp\/openresty-${OPENRESTY_VERSION}\nRUN .\/configure --prefix=\/usr\/local\/openresty \\\n                --with-pcre-jit \\\n                --with-http_ssl_module \\\n                --with-http_v2_module \\\n                --with-http_realip_module \\\n                --with-http_stub_status_module \\\n                -j2 &amp;&amp; \\\n    make &amp;&amp; \\\n    make install\n \n# \u5265\u79bb\u53ef\u6267\u884c\u6587\u4ef6\nRUN strip \/usr\/local\/openresty\/nginx\/sbin\/nginx\n \n# stage 2: \u6700\u7ec8\u8fd0\u884c\u73af\u5883\nFROM alpine:3.21.3\n \n# \u5b89\u88c5\u8fd0\u884c\u65f6\u4f9d\u8d56\n \n# \u5b89\u88c5\u8fd0\u884c\u65f6\u4f9d\u8d56\u4e0e\u65f6\u533a\u652f\u6301\nRUN sed -i 's|https:\/\/dl-cdn.alpinelinux.org\/alpine|https:\/\/mirrors.aliyun.com\/alpine|g' \/etc\/apk\/repositories &amp;&amp; \\\n    apk add --no-cache \\\n    libgcc \\\n    pcre \\\n    openssl \\\n    zlib \\\n    tzdata &amp;&amp; \\\n    cp \/usr\/share\/zoneinfo\/Asia\/Shanghai \/etc\/localtime &amp;&amp; \\\n    echo \"Asia\/Shanghai\" > \/etc\/timezone\n \n# \u590d\u5236\u7f16\u8bd1\u597d\u7684 OpenResty \u6587\u4ef6\nCOPY --from=builder \/usr\/local\/openresty \/usr\/local\/openresty\n \n# \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\u548c\u73af\u5883\u53d8\u91cf\nWORKDIR \/usr\/local\/openresty\nENV PATH \"\/usr\/local\/openresty\/bin:\/usr\/local\/openresty\/nginx\/sbin:$PATH\"\n\n# \u66b4\u9732\u7aef\u53e3\nEXPOSE 80\n \n# \u542f\u52a8\u547d\u4ee4\nCMD &#91;\"nginx\", \"-g\", \"daemon off;\"]\n<\/code><\/pre>\n\n\n\n<p>\u9644\u4ef6\u4e0b\u8f7d\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/opshub.com.cn\/wp-content\/uploads\/2026\/02\/openresty.zip\">openresty.zip<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u9636\u6bb5\u6784\u5efa OpenResty\u7684 Dockerfile\uff0c\u57fa\u4e8e debian:stable-slim\uff0c\u6838\u5fc3\u505a\u4e86 OpenResty \u6e90\u7801\u7f16\u8bd1\uff08\u589e\u5927 nginx \u9519\u8bef\u65e5\u5fd7\u6700\u5927\u5b57\u7b26\u4e32\u957f\u5ea6\uff09\u3001\u7cbe\u7b80\u6784\u5efa\u4ea7\u7269\u3001\u6700\u7ec8\u751f\u6210\u8f7b\u91cf\u8fd0\u884c\u955c\u50cf\u7684\u64cd\u4f5c \u57fa\u4e8e Alpine 3.21.3 \u7684 OpenResty \u591a\u9636\u6bb5\u6784\u5efa Dockerfile\uff0c\u76f8\u6bd4\u4e4b\u524d\u7684 Debian \u7248\u672c\uff0cAlpine \u672c\u8eab\u662f\u8f7b\u91cf Linux \u53d1\u884c\u7248\uff0c\u6700\u7ec8\u955c\u50cf\u4f53\u79ef\u4f1a\u66f4\u5c0f\uff0c\u8fd8\u505a\u4e86\u65f6\u533a\u914d\u7f6e\u3001\u5f00\u542f\u66f4\u591a Nginx \u5b9e\u7528\u6a21\u5757\u3001\u76f4\u63a5\u5728\u7ebf\u4e0b\u8f7d\u6e90\u7801\u7b49\u4f18\u5316 \u9644\u4ef6\u4e0b\u8f7d\uff1a openresty.zip<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-837","post","type-post","status-publish","format-standard","hentry","category-dockerkubernetes"],"_links":{"self":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=837"}],"version-history":[{"count":1,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/837\/revisions"}],"predecessor-version":[{"id":839,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/837\/revisions\/839"}],"wp:attachment":[{"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opshub.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}