{"id":2181,"date":"2025-07-01T15:32:33","date_gmt":"2025-07-01T07:32:33","guid":{"rendered":"https:\/\/www.madbull.site\/?p=2181"},"modified":"2025-12-12T16:39:17","modified_gmt":"2025-12-12T08:39:17","slug":"docker%e5%88%b6%e4%bd%9cpython%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/www.madbull.site\/?p=2181","title":{"rendered":"Docker\u5236\u4f5cpython\u73af\u5883"},"content":{"rendered":"\n<p>\u5206\u4eab\u4e00\u4e2a\u7528docker\u5236\u4f5c\u4e0d\u540cpython\u73af\u5883\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>python\u7684\u7248\u672c\u66f4\u65b0\u5f88\u5feb\uff0c\u8fd9\u4e9b\u7248\u672c\u90fd\u53ef\u4ee5\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5230\u6e90\u7801\u3002\u5728\u5de5\u4f5c\u4e2d\u6d89\u53ca\u7ed9\u8001\u4ee3\u7801\u642d\u5efa\u73af\u5883\u7684\u95ee\u9898\uff0c\u800c\u7cfb\u7edf\u6e90\u91cc\u5f88\u6709\u53ef\u80fd\u662f\u6ca1\u6709\u5bf9\u5e94\u7684python\u7248\u672c\u7684\uff0c\u8fd9\u65f6\u5019\uff0c\u6211\u4eec\u5c31\u9700\u8981\u624b\u52a8\u642d\u5efa\u73af\u5883\u4e86\u3002\u5728\u7cfb\u7edf\u4e2d\u642d\u5efa\u7684\u65b9\u6cd5\u53ef\u4ee5\u67e5\u770b\u5f80\u671f\u6587\u7ae0\uff1a<a href=\"https:\/\/www.madbull.site\/?p=1933\">https:\/\/www.madbull.site\/?p=1933<\/a><\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u4e0b\u8f7d\u4e86\u6e90\u7801\uff0c\u5236\u4f5cdocker\u955c\u50cf\u5c31\u6bd4\u8f83\u7b80\u5355\u4e86\u3002\u4e0b\u9762\u662f\u4ee5python3.7.8\u4e3a\u4f8b\u5236\u4f5c\u7684Dockerfile \u6587\u4ef6\u3002\u7cfb\u7edf\u955c\u50cf\u4f7f\u7528\u7684\u963f\u91cc\u9f99\u87258.6\u73af\u5883\uff08CentOS\u7684\u5e73\u66ff\u7cfb\u7edf\uff09\u3002\u5728\u56fd\u5185\u5b98\u7f51docker\u7684\u6e90\u4e0d\u592a\u53cb\u597d\uff0c\u6240\u6709\u9700\u8981\u4fee\u6539\u4e00\u4e0bdocker\u6e90\u4e3a\u56fd\u5185\u7684\u955c\u50cf\uff0c\u8fd9\u6837\u4e0b\u8f7d\u66f4\u5feb\u66f4\u65b9\u4fbf\u3002\u4fee\u6539\u6e90\u5177\u4f53\u65b9\u6cd5\u67e5\u770b\u5f80\u671f\u6587\u7ae0\uff1a<a href=\"https:\/\/www.madbull.site\/?p=2060\">https:\/\/www.madbull.site\/?p=2060<\/a> <strong>\u5b89\u88c5\u8fd0\u884c<\/strong> \u5c0f\u8282\u3002<\/p>\n\n\n\n<div style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30);height:0px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4f7f\u7528 OpenAnolis 8.6 \u4f5c\u4e3a\u57fa\u7840\u955c\u50cf\nFROM anolisos:8.6\n\n# \u8bbe\u7f6e\u7cfb\u7edf\u6e90\nRUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \\\n         -e 's|^#baseurl=http:\/\/mirrors.tuna.tsinghua.edu.cn\/anolis|baseurl=https:\/\/mirrors.aliyun.com\/anolis|g' \\\n         -i.bak \/etc\/yum.repos.d\/*.repo\n\n# \u5b89\u88c5\u7f16\u8bd1 Python 3.7 \u6240\u9700\u7684\u4f9d\u8d56\nRUN dnf update -y &amp;&amp; \\\n    dnf groupinstall -y \"Development Tools\" &amp;&amp; \\\n    dnf install -y \\\n        wget \\\n        gcc \\\n        make \\\n        zlib-devel \\\n        bzip2-devel \\\n        readline-devel \\\n        sqlite-devel \\\n        openssl-devel \\\n        ncurses-devel \\\n        tk-devel \\\n        libffi-devel \\\n        xz-devel \\\n        gdbm-devel \\\n        vim \\\n        net-tools \\\n        tzdata &amp;&amp; \\\n    dnf clean all\n\n# \u8bbe\u7f6e\u65f6\u533a\u4e3a\u4e0a\u6d77\nRUN ln -sf \/usr\/share\/zoneinfo\/Asia\/Shanghai \/etc\/localtime &amp;&amp; \\\n    echo \"Asia\/Shanghai\" &gt; \/etc\/timezone\n\n# \u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\nENV LANG C.UTF-8\nENV LC_ALL C.UTF-8\nENV PYTHONUNBUFFERED 1\n\n# \u4e0b\u8f7d\u5e76\u7f16\u8bd1\u5b89\u88c5 Python 3.7\u3002\u76f4\u63a5\u4e0b\u8f7d\u53ef\u80fd\u4f1a\u4e0b\u8f7d\u5931\u8d25\uff0c\u53ef\u4ee5\u7528\u6d4f\u89c8\u5668\u4e0b\u8f7d\u597d\u540eCOPY\u5230\u955c\u50cf\u3002\n#    wget https:\/\/www.python.org\/ftp\/python\/3.7.8\/Python-3.7.8.tgz \nCOPY Python-3.7.8.tgz .\nRUN tar xzf Python-3.7.8.tgz &amp;&amp; \\\n    cd Python-3.7.8 &amp;&amp; \\\n    .\/configure --enable-optimizations --enable-shared --prefix=\/usr\/local LDFLAGS=\"-Wl,-rpath \/usr\/local\/lib\" &amp;&amp; \\\n    make -j$(nproc) &amp;&amp; \\\n    make altinstall &amp;&amp; \\\n    rm -rf Python-3.7.8*\n\n# \u521b\u5efa\u7b26\u53f7\u94fe\u63a5\nRUN ln -s \/usr\/local\/bin\/python3.7 \/usr\/local\/bin\/python3 &amp;&amp; \\\n    ln -s \/usr\/local\/bin\/pip3.7 \/usr\/local\/bin\/pip3\n\n# \u914d\u7f6epip\nRUN pip3.7 config set global.index-url https:\/\/pypi.doubanio.com\/simple\n\n# \u5b89\u88c5\u4f9d\u8d56 requirements.txt \u662f python\u670d\u52a1 \u9700\u8981\u5b89\u88c5\u7684\u5e93\u3002\nCOPY requirements.txt \/app\/requirements.txt\nRUN pip3.7 install --no-cache-dir -r \/app\/requirements.txt\n\n# \u53e6\u5916\uff0c\u5bf9\u4e8epython2.X\uff0c\u5b98\u65b9\u5df2\u7ecf\u4e0d\u518d\u652f\u6301\u4e86\uff0c\u5c31\u7b97\u5b98\u7f51\u652f\u6301\uff0c\u4f46\u662f\u8fd8\u662f\u6709\u4e00\u4e9b\u5e93pip\u4e0b\u8f7d\u4e0d\u5230\u7684\u60c5\u51b5\uff0c\u600e\u4e48\u529e\u5462\uff1f\n# \u6ce8\u610f\u5230\uff1a\u5728\u7f16\u8bd1\u7684\u65f6\u5019\uff0c\u6211\u4eec\u628apython3.7\u7684\u5e93\u5b89\u88c5\u5728\u4e86 \/usr\/local\/lib\/python3.7\/\uff0c\u5982\u679cpip\u6e90\u91cc\u627e\u4e0d\u5230\uff0c\u800c\u6211\u4eec\u624b\u91cc\u6709\u5bf9\u5e94\u7248\u672c\u7684\u5e93\u3002\u53ef\u4ee5\u76f4\u63a5\u628a\u4f9d\u8d56\u590d\u5236\u5230 \/usr\/local\/lib\/python3.7\/site-packages \u76ee\u5f55\u4e0b\u5373\u53ef\u3002\n# \u4f8b\u5982\uff0cyara\u7684\u5e93\u5c31\u6574\u7406\u7684\u4e0d\u592a\u597d\uff0c\u6211\u5c31\u662f\u76f4\u63a5\u62ff\u539f\u7cfb\u7edf\u7684\u5e93\u6574\u7406\u7684\u3002\nCOPY yara_python-4.2.0-py3.7-linux-x86_64.egg\/yara.py \/usr\/local\/lib\/python3.7\/site-packages\/yara.py\nCOPY yara_python-4.2.0-py3.7-linux-x86_64.egg\/yara.cpython-37m-x86_64-linux-gnu.so \/usr\/local\/lib\/python3.7\/site-packages\/yara.cpython-37m-x86_64-linux-gnu.so\nCOPY yara_python-4.2.0-py3.7-linux-x86_64.egg\/libyara.so.9.0.1 \/lib\/libyara.so.9.0.1\nRUN ln -s \/lib\/libyara.so.9.0.1 \/lib\/libyara.so.9 &amp;&amp; ldconfig\n\n# \u8bbe\u7f6e\u5de5\u4f5c\u76ee\u5f55\nWORKDIR \/app\n\n# \u62f7\u8d1d\u4f60\u7684python\u670d\u52a1\nCOPY YOUR_SERVER \/app\/YOUR_SERVER\n\n# \u53ef\u4ee5\u521b\u5efa\u4f60\u9700\u8981\u7684\u76ee\u5f55\uff0c\u8fd0\u884c\u65f6\u53ef\u4ee5\u8bbe\u7f6e\u6302\u8f7d\u5bbf\u4e3b\u673a\u7684\u76ee\u5f55\u3002\nRUN mkdir -p \/app\/log \/data\n\n# \u542f\u52a8\u547d\u4ee4\u3002\u6ce8\u610f\uff1a\u8fd9\u91cc\u4e00\u5b9a\u4e0d\u8981\u540e\u53f0\u8fd0\u884c\u3002\u5982\u679c\u8f6c\u4e3a\u540e\u53f0\uff0c\u5219\u4f1a\u88ab\u8ba4\u4e3adocker\u5df2\u8fd0\u884c\u5b8c\u6210\u3002\nCMD &#91;\"python3.7\", \"YOUR_SERVER\/YOUR_SERVER.py\"]\n<\/code><\/pre>\n\n\n\n<p><strong>\u907f\u5751\uff1a<\/strong> Dockerfile \u6587\u4ef6\u4e2d\u7684 COPY \u6307\u4ee4\uff0c\u5982\u679c\u60f3\u590d\u5236\u4e00\u4e2a\u76ee\u5f55\uff0c\u4f1a\u628a\u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\u590d\u5236\u5230\u76ee\u6807\u8def\u5f84\uff0c\u800c\u76ee\u5f55\u4e0d\u4f1a\u672c\u8eab\u4e0d\u4f1a\u590d\u5236\u8fc7\u53bb\u3002\u4f8b\u5982:<\/p>\n\n\n\n<p>\u60f3\u628a source \u76ee\u5f55 \u590d\u5236\u5230 \u865a\u62df\u673a\u7684 \/data\/ \u76ee\u5f55\u4e0b\uff0c\u5fc5\u987b\u5199\uff1aCOPY source \/data\/source\/ \uff0c\u800c\u4e0d\u662f COPY source \/data\/ <\/p>\n\n\n\n<p>\u8fd9\u6837 \u865a\u62df\u673a\u4f1a\u521b\u5efa \/data\/soruce\/ \u76ee\u5f55\uff0c\u5e76\u628a source \u76ee\u5f55\u4e0b\u7684\u6587\u4ef6\uff0c\u590d\u5236\u5230 \/data\/source\/ \u76ee\u5f55\u4e0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Docker\u5236\u4f5cpython\u73af\u5883<\/p>\n","protected":false},"author":1,"featured_media":1044,"comment_status":"open","ping_status":"open","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[166,131,154],"tags":[145,283,142],"class_list":["post-2181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tools","category-131","category-154","tag-docker","tag-dockerfile","tag-python"],"_links":{"self":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2181"}],"version-history":[{"count":2,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions"}],"predecessor-version":[{"id":2445,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions\/2445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=\/wp\/v2\/media\/1044"}],"wp:attachment":[{"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.madbull.site\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}