{"id":422555,"date":"2024-12-03T12:25:49","date_gmt":"2024-12-03T04:25:49","guid":{"rendered":"https:\/\/www.idc.net\/help\/422555\/"},"modified":"2024-12-03T12:25:49","modified_gmt":"2024-12-03T04:25:49","slug":"docker%e7%9a%84%e5%ae%b9%e5%99%a8%e9%95%9c%e5%83%8f%e4%bc%98%e5%8c%96%e4%b8%8e%e7%bc%93%e5%ad%98%e7%ad%96%e7%95%a5%ef%bc%8c%e5%87%8f%e5%b0%91%e6%8b%89%e5%8f%96%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/422555\/","title":{"rendered":"Docker\u7684\u5bb9\u5668\u955c\u50cf\u4f18\u5316\u4e0e\u7f13\u5b58\u7b56\u7565\uff0c\u51cf\u5c11\u62c9\u53d6\u65f6\u95f4"},"content":{"rendered":"<h1 id=\"docker%e7%9a%84%e5%ae%b9%e5%99%a8%e9%95%9c%e5%83%8f%e4%bc%98%e5%8c%96%e4%b8%8e%e7%bc%93%e5%ad%98%e7%ad%96%e7%95%a5%ef%bc%8c%e5%87%8f%e5%b0%91%e6%8b%89%e5%8f%96%e6%97%b6%e9%97%b4-rnEYlXxKHx\">Docker\u7684\u5bb9\u5668\u955c\u50cf\u4f18\u5316\u4e0e\u7f13\u5b58\u7b56\u7565\uff0c\u51cf\u5c11\u62c9\u53d6\u65f6\u95f4<\/h1>\n<p>\u5728\u73b0\u4ee3\u8f6f\u4ef6\u5f00\u53d1\u4e2d\uff0cDocker\u5df2\u7ecf\u6210\u4e3a\u4e00\u79cd\u6d41\u884c\u7684\u5bb9\u5668\u5316\u6280\u672f\u3002\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u5c06\u5e94\u7528\u7a0b\u5e8f\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u5230\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5bb9\u5668\u4e2d\uff0c\u4ece\u800c\u5b9e\u73b0\u66f4\u9ad8\u6548\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u3002\u7136\u800c\uff0c\u968f\u7740\u5bb9\u5668\u955c\u50cf\u7684\u589e\u5927\uff0c\u62c9\u53d6\u955c\u50cf\u6240\u9700\u7684\u65f6\u95f4\u4e5f\u968f\u4e4b\u589e\u52a0\uff0c\u8fd9\u5bf9\u5f00\u53d1\u548c\u8fd0\u7ef4\u56e2\u961f\u7684\u6548\u7387\u9020\u6210\u4e86\u5f71\u54cd\u3002\u56e0\u6b64\uff0c\u4f18\u5316Docker\u5bb9\u5668\u955c\u50cf\u548c\u91c7\u7528\u6709\u6548\u7684\u7f13\u5b58\u7b56\u7565\u663e\u5f97\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e5%ae%b9%e5%99%a8%e9%95%9c%e5%83%8f%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-rnEYlXxKHx\">\u5bb9\u5668\u955c\u50cf\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Docker\u5bb9\u5668\u955c\u50cf\u662f\u4e00\u4e2a\u53ea\u8bfb\u7684\u6a21\u677f\uff0c\u5305\u542b\u4e86\u8fd0\u884c\u67d0\u4e2a\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u6587\u4ef6\u548c\u4f9d\u8d56\u9879\u3002\u955c\u50cf\u7531\u591a\u4e2a\u5c42\u7ec4\u6210\uff0c\u6bcf\u4e00\u5c42\u90fd\u4ee3\u8868\u4e86\u6587\u4ef6\u7cfb\u7edf\u7684\u4e00\u4e2a\u53d8\u66f4\u3002Docker\u4f7f\u7528\u5206\u5c42\u6587\u4ef6\u7cfb\u7edf\uff0c\u8fd9\u610f\u5473\u7740\u5982\u679c\u67d0\u4e00\u5c42\u6ca1\u6709\u53d8\u5316\uff0cDocker\u53ef\u4ee5\u91cd\u7528\u8be5\u5c42\uff0c\u4ece\u800c\u8282\u7701\u5b58\u50a8\u7a7a\u95f4\u548c\u62c9\u53d6\u65f6\u95f4\u3002<\/p>\n<h2 id=\"%e4%bc%98%e5%8c%96%e5%ae%b9%e5%99%a8%e9%95%9c%e5%83%8f%e7%9a%84%e7%ad%96%e7%95%a5-rnEYlXxKHx\">\u4f18\u5316\u5bb9\u5668\u955c\u50cf\u7684\u7b56\u7565<\/h2>\n<h3 id=\"1-%e7%b2%be%e7%ae%80%e5%9f%ba%e7%a1%80%e9%95%9c%e5%83%8f-rnEYlXxKHx\">1. \u7cbe\u7b80\u57fa\u7840\u955c\u50cf<\/h3>\n<p>\u9009\u62e9\u4e00\u4e2a\u5c0f\u5de7\u7684\u57fa\u7840\u955c\u50cf\u662f\u4f18\u5316\u7684\u7b2c\u4e00\u6b65\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>alpine<\/code>\u955c\u50cf\u4ee3\u66ff<code>ubuntu<\/code>\u6216<code>debian<\/code>\uff0c\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u955c\u50cf\u7684\u5927\u5c0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code>FROM alpine:latest\nRUN apk add --no-cache python3\nCOPY . \/app\nCMD [\"python3\", \"\/app\/app.py\"]\n<\/code><\/pre>\n<h3 id=\"2-%e5%90%88%e5%b9%b6%e5%91%bd%e4%bb%a4-rnEYlXxKHx\">2. \u5408\u5e76\u547d\u4ee4<\/h3>\n<p>\u5728Dockerfile\u4e2d\uff0c\u5c3d\u91cf\u5c06\u591a\u4e2a<code>RUN<\/code>\u547d\u4ee4\u5408\u5e76\u4e3a\u4e00\u4e2a\uff0c\u4ee5\u51cf\u5c11\u955c\u50cf\u5c42\u7684\u6570\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>RUN apk update &amp;&amp; apk add --no-cache python3 &amp;&amp; apk add --no-cache curl\n<\/code><\/pre>\n<h3 id=\"3-%e6%b8%85%e7%90%86%e4%b8%8d%e5%bf%85%e8%a6%81%e7%9a%84%e6%96%87%e4%bb%b6-rnEYlXxKHx\">3. \u6e05\u7406\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6<\/h3>\n<p>\u5728\u6784\u5efa\u955c\u50cf\u65f6\uff0c\u786e\u4fdd\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6\u548c\u7f13\u5b58\u3002\u4f8b\u5982\uff0c\u5728\u4f7f\u7528<code>apt-get<\/code>\u65f6\uff0c\u53ef\u4ee5\u6dfb\u52a0<code>apt-get clean<\/code>\u547d\u4ee4\u6765\u6e05\u7406\u7f13\u5b58\uff1a<\/p>\n<pre><code>RUN apt-get update &amp;&amp; apt-get install -y \n    python3 \n    &amp;&amp; apt-get clean \n    &amp;&amp; rm -rf \/var\/lib\/apt\/lists\/*\n<\/code><\/pre>\n<h2 id=\"%e7%bc%93%e5%ad%98%e7%ad%96%e7%95%a5%e7%9a%84%e5%ba%94%e7%94%a8-rnEYlXxKHx\">\u7f13\u5b58\u7b56\u7565\u7684\u5e94\u7528<\/h2>\n<h3 id=\"1-%e5%88%a9%e7%94%a8docker%e7%bc%93%e5%ad%98%e6%9c%ba%e5%88%b6-rnEYlXxKHx\">1. \u5229\u7528Docker\u7f13\u5b58\u673a\u5236<\/h3>\n<p>Docker\u5728\u6784\u5efa\u955c\u50cf\u65f6\u4f1a\u7f13\u5b58\u6bcf\u4e00\u5c42\uff0c\u5982\u679c\u67d0\u4e00\u5c42\u6ca1\u6709\u53d8\u5316\uff0cDocker\u4f1a\u76f4\u63a5\u4f7f\u7528\u7f13\u5b58\u3002\u8fd9\u610f\u5473\u7740\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5c3d\u91cf\u5c06\u4e0d\u5e38\u53d8\u5316\u7684\u547d\u4ee4\u653e\u5728Dockerfile\u7684\u524d\u9762\uff0c\u4ee5\u63d0\u9ad8\u6784\u5efa\u901f\u5ea6\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e7%a7%81%e6%9c%89%e9%95%9c%e5%83%8f%e4%bb%93%e5%ba%93-rnEYlXxKHx\">2. \u4f7f\u7528\u79c1\u6709\u955c\u50cf\u4ed3\u5e93<\/h3>\n<p>\u4e3a\u4e86\u51cf\u5c11\u62c9\u53d6\u65f6\u95f4\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u79c1\u6709\u955c\u50cf\u4ed3\u5e93\u3002\u901a\u8fc7\u5c06\u5e38\u7528\u7684\u955c\u50cf\u63a8\u9001\u5230\u79c1\u6709\u4ed3\u5e93\uff0c\u56e2\u961f\u6210\u5458\u53ef\u4ee5\u66f4\u5feb\u5730\u62c9\u53d6\u955c\u50cf\uff0c\u907f\u514d\u4ece\u516c\u5171\u4ed3\u5e93\u4e0b\u8f7d\u7684\u5ef6\u8fdf\u3002<\/p>\n<h3 id=\"3-%e9%95%9c%e5%83%8f%e5%88%86%e5%b1%82%e7%ae%a1%e7%90%86-rnEYlXxKHx\">3. \u955c\u50cf\u5206\u5c42\u7ba1\u7406<\/h3>\n<p>\u5728\u6784\u5efa\u955c\u50cf\u65f6\uff0c\u5408\u7406\u7ba1\u7406\u955c\u50cf\u7684\u5206\u5c42\u7ed3\u6784\uff0c\u53ef\u4ee5\u6709\u6548\u5229\u7528\u7f13\u5b58\u3002\u4f8b\u5982\uff0c\u9891\u7e41\u53d8\u52a8\u7684\u6587\u4ef6\u53ef\u4ee5\u653e\u5728\u955c\u50cf\u7684\u6700\u540e\u4e00\u5c42\uff0c\u800c\u4e0d\u5e38\u53d8\u52a8\u7684\u4f9d\u8d56\u9879\u5219\u653e\u5728\u524d\u9762\u3002<\/p>\n<h2 id=\"%e6%80%bb%e7%bb%93-rnEYlXxKHx\">\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u7cbe\u7b80\u57fa\u7840\u955c\u50cf\u3001\u5408\u5e76\u547d\u4ee4\u3001\u6e05\u7406\u4e0d\u5fc5\u8981\u7684\u6587\u4ef6\u4ee5\u53ca\u5408\u7406\u5229\u7528Docker\u7684\u7f13\u5b58\u673a\u5236\uff0c\u53ef\u4ee5\u663e\u8457\u4f18\u5316Docker\u5bb9\u5668\u955c\u50cf\uff0c\u51cf\u5c11\u62c9\u53d6\u65f6\u95f4\u3002\u8fd9\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\uff0c\u4e5f\u4e3a\u8fd0\u7ef4\u5e26\u6765\u4e86\u4fbf\u5229\u3002\u5bf9\u4e8e\u9700\u8981\u9ad8\u6548\u7ba1\u7406\u548c\u90e8\u7f72\u7684\u4f01\u4e1a\uff0c\u9009\u62e9\u5408\u9002\u7684\u4e91\u670d\u52a1\u63d0\u4f9b\u5546\uff0c\u5982\u540e\u6d6a\u4e91\uff0c\u80fd\u591f\u8fdb\u4e00\u6b65\u63d0\u5347\u6574\u4f53\u6027\u80fd\u3002\u540e\u6d6a\u4e91\u63d0\u4f9b\u591a\u79cd\u4e91\u670d\u52a1\uff0c\u5305\u62ec<a href=\"https:\/\/idc.net\">\u9999\u6e2fvps<\/a>\u3001<a href=\"https:\/\/idc.net\">\u7f8e\u56fd\u670d\u52a1\u5668<\/a>\u7b49\uff0c\u52a9\u529b\u4f01\u4e1a\u5b9e\u73b0\u66f4\u9ad8\u6548\u7684\u4e91\u8ba1\u7b97\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f18\u5316Docker\u5bb9\u5668\u955c\u50cf\u4e0e\u7f13\u5b58<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[202757],"tags":[],"class_list":["post-422555","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/422555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=422555"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/422555\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=422555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=422555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=422555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}