{"id":63434,"date":"2025-04-29T10:05:13","date_gmt":"2025-04-29T02:05:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63434\/"},"modified":"2025-04-29T10:05:13","modified_gmt":"2025-04-29T02:05:13","slug":"dockerfile%e6%80%8e%e4%b9%88%e7%94%a8-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63434\/","title":{"rendered":"dockerfile\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  dockerfile \u662f\u7528\u4e8e\u6784\u5efa docker \u955c\u50cf\u7684\u6587\u672c\u6587\u4ef6\uff0c\u5305\u542b\u6307\u793a docker \u6784\u5efa\u955c\u50cf\u7684\u6307\u4ee4\u3002\u5176\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa dockerfile \u6587\u672c\u6587\u4ef6\u3002\u6307\u5b9a\u57fa\u7840\u955c\u50cf\u3002\u4f7f\u7528 copy \u6307\u4ee4\u590d\u5236\u6587\u4ef6\u5230\u955c\u50cf\u3002\u4f7f\u7528 run \u6307\u4ee4\u8fd0\u884c\u547d\u4ee4\u3002\u4f7f\u7528 env \u6307\u4ee4\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f7f\u7528 entrypoint \u6307\u4ee4\u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u547d\u4ee4\u3002\u6784\u5efa\u955c\u50cf\uff1adocker build -t my-image .\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202404\/02\/2024040222211848840.jpg\" class=\"aligncenter\" title=\"dockerfile\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"dockerfile\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Dockerfile<\/strong><\/p>\n<p>Dockerfile \u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u7528\u4e8e\u6784\u5efa Docker \u955c\u50cf\u3002\u5b83\u5305\u542b\u4e00\u7cfb\u5217\u6307\u4ee4\uff0c\u6307\u5bfc Docker \u5982\u4f55\u4ece\u57fa\u7840\u955c\u50cf\u521b\u5efa\u65b0\u955c\u50cf\u3002<\/p>\n<p><strong>\u4f7f\u7528 Dockerfile \u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa Dockerfile:<\/strong> \u5728\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u547d\u540d\u4e3a &#8220;Dockerfile&#8221;\uff08\u4e0d\u5e26\u6269\u5c55\u540d\uff09\u3002<\/li>\n<li>\n<p><strong>\u6307\u5b9a\u57fa\u7840\u955c\u50cf:<\/strong> \u7b2c\u4e00\u884c\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u57fa\u7840\u955c\u50cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>FROM ubuntu:latest<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u590d\u5236\u6587\u4ef6:<\/strong> \u4f7f\u7528 COPY \u6307\u4ee4\u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55\u5230\u955c\u50cf\u4e2d\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>COPY requirements.txt \/app<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u8fd0\u884c\u547d\u4ee4:<\/strong> \u4f7f\u7528 RUN \u6307\u4ee4\u5728\u955c\u50cf\u4e2d\u8fd0\u884c\u547d\u4ee4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>RUN pip install -r requirements.txt<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf:<\/strong> \u4f7f\u7528 ENV \u6307\u4ee4\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>ENV MY_VARIABLE=\"my value\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u521b\u5efa\u5165\u53e3\u70b9:<\/strong> \u4f7f\u7528 ENTRYPOINT \u6307\u4ee4\u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u65f6\u8981\u8fd0\u884c\u7684\u547d\u4ee4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>ENTRYPOINT [\"python\", \"main.py\"]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6784\u5efa\u955c\u50cf:<\/strong> \u5728\u5305\u542b Dockerfile \u7684\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>docker build -t my-image .<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b Dockerfile\uff1a<\/strong><\/p>\n<pre>FROM ubuntu:latest\n\nCOPY requirements.txt \/app\nRUN pip install -r requirements.txt\n\nENV MY_VARIABLE=\"my value\"\n\nENTRYPOINT [\"python\", \"main.py\"]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a Dockerfile \u4f1a\u521b\u5efa\u4e00\u4e2a\u57fa\u4e8e Ubuntu \u955c\u50cf\u7684\u955c\u50cf\uff0c\u5b89\u88c5 Python \u4f9d\u8d56\u9879\uff0c\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u5e76\u5728\u5bb9\u5668\u542f\u52a8\u65f6\u8fd0\u884c Python \u811a\u672c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662ffile\u600e\u4e48\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>dockerfile \u662f\u7528\u4e8e\u6784\u5efa docker \u955c\u50cf\u7684\u6587\u672c\u6587\u4ef6\uff0c\u5305\u542b\u6307\u793a docker \u6784\u5efa\u955c\u50cf\u7684\u6307\u4ee4\u3002\u5176\u4f7f\u7528\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa dockerfile \u6587\u672c\u6587\u4ef6\u3002\u6307\u5b9a\u57fa\u7840\u955c\u50cf\u3002\u4f7f\u7528 copy \u6307\u4ee4\u590d\u5236\u6587\u4ef6\u5230\u955c\u50cf\u3002\u4f7f\u7528 run \u6307\u4ee4\u8fd0\u884c\u547d\u4ee4\u3002\u4f7f\u7528 env \u6307\u4ee4\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f7f\u7528 entrypoint \u6307\u4ee4\u6307\u5b9a\u5bb9\u5668\u542f\u52a8\u547d\u4ee4\u3002\u6784\u5efa\u955c\u50cf\uff1adocker build -t my-image . \u5982\u4f55\u4f7f\u7528 Dockerfile Dockerfile \u662f\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u7528\u4e8e\u6784\u5efa Docker \u955c\u50cf\u3002\u5b83\u5305\u542b\u4e00\u7cfb\u5217\u6307\u4ee4\uff0c\u6307\u5bfc Docker \u5982\u4f55\u4ece\u57fa\u7840\u955c\u50cf\u521b\u5efa\u65b0\u955c\u50cf\u3002 \u4f7f\u7528 Dockerfile \u7684\u6b65\u9aa4\uff1a \u521b\u5efa Dockerfile: \u5728\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u547d\u540d\u4e3a &#8220;Dockerfile&#8221;\uff08\u4e0d\u5e26\u6269\u5c55\u540d\uff09\u3002 \u6307\u5b9a\u57fa\u7840\u955c\u50cf: \u7b2c\u4e00\u884c\u6307\u5b9a\u8981\u4f7f\u7528\u7684\u57fa\u7840\u955c\u50cf\u3002\u4f8b\u5982\uff1a FROM ubuntu:latest \u767b\u5f55\u540e\u590d\u5236 \u590d\u5236\u6587\u4ef6: \u4f7f\u7528 COPY \u6307\u4ee4\u590d\u5236\u6587\u4ef6\u6216\u76ee\u5f55\u5230\u955c\u50cf\u4e2d\u3002\u4f8b\u5982\uff1a COPY requirements.txt \/app \u767b\u5f55\u540e\u590d\u5236 \u8fd0\u884c\u547d\u4ee4: \u4f7f\u7528 RUN \u6307\u4ee4\u5728\u955c\u50cf\u4e2d\u8fd0\u884c\u547d\u4ee4\u3002\u4f8b\u5982\uff1a RUN pip install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63434","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63434"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63434\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}