{"id":4225,"date":"2024-11-11T17:23:14","date_gmt":"2024-11-11T09:23:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/4225\/"},"modified":"2024-11-11T17:23:14","modified_gmt":"2024-11-11T09:23:14","slug":"%e5%b0%86-python-%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e5%ae%b9%e5%99%a8%e5%8c%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/4225\/","title":{"rendered":"\u5c06 Python \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316"},"content":{"rendered":"<h1>\u5c06 Python \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316<\/h1>\n<h2><\/h2>\n<ul>\n<li>\u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002<\/li>\n<li>\u4f60\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u672c\u90e8\u5206\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u5bb9\u5668\u5316\u548c\u8fd0\u884c Python \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2><\/h2>\n<p>\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u6d41\u884c\u7684 \u6846\u67b6\u3002<\/p>\n<p>\u514b\u9686\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u4ee5\u4e0e\u672c\u6307\u5357\u4e00\u8d77\u4f7f\u7528\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u5c06\u76ee\u5f55\u66f4\u6539\u4e3a\u60a8\u60f3\u8981\u5de5\u4f5c\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u514b\u9686\u5b58\u50a8\u5e93\uff1a<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> git clone https:\/\/github.com\/docker\/python-docker <\/span><\/span><\/code><\/pre>\n<h2><\/h2>\n<p>\u73b0\u5728\u60a8\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u7528\u6765<code>docker init<\/code>\u521b\u5efa\u5fc5\u8981\u7684 Docker \u8d44\u4ea7\u6765\u5bb9\u5668\u5316\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u76ee\u5f55\u4e2d <code>python-docker<\/code>\uff0c\u8fd0\u884c<code>docker init<\/code>\u547d\u4ee4\u3002<code>docker init<\/code>\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e\uff0c\u4f46\u60a8\u9700\u8981\u56de\u7b54\u4e00\u4e9b\u6709\u5173\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u8fd9\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528Flask\u6765\u8fd0\u884c\u3002\u8bf7\u53c2\u9605\u4ee5\u4e0b\u793a\u4f8b\u6765\u56de\u7b54\u63d0\u793a\uff0c<code>docker init<\/code>\u5e76\u5bf9\u63d0\u793a\u4f7f\u7528\u76f8\u540c\u7684\u7b54\u6848\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker init <\/span><\/span><span><span><span>Welcome to the Docker Init CLI! <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>This utility will walk you through creating the following files with sensible defaults for your project: <\/span><\/span><\/span><span><span><span> - .dockerignore <\/span><\/span><\/span><span><span><span> - Dockerfile <\/span><\/span><\/span><span><span><span> - compose.yaml <\/span><\/span><\/span><span><span><span> - README.Docker.md <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>Let's get started! <\/span><\/span><\/span><span><span><span><\/span><span> <\/span><\/span><\/span><span><span><span><\/span><span>? What application platform does your project use? Python <\/span><\/span><\/span><span><span><span>? What version of Python do you want to use? 3.11.4 <\/span><\/span><\/span><span><span><span>? What port do you want your app to listen on? 5000 <\/span><\/span><\/span><span><span><span>? What is the command to run your app? python3 -m flask run --host=0.0.0.0 <\/span><\/span><\/span><\/code><\/pre>\n<p>\u60a8\u7684\u76ee\u5f55\u4e2d\u73b0\u5728\u5e94\u8be5\u6709\u4ee5\u4e0b\u5185\u5bb9<code>python-docker<\/code> \u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span>\u251c\u2500\u2500 python-docker\/ <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 app.py <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 requirements.txt <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 .dockerignore <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 compose.yaml <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 Dockerfile <\/span><\/span><span><span>\u2502 \u251c\u2500\u2500 README.Docker.md <\/span><\/span><span><span>\u2502 \u2514\u2500\u2500 README.md<\/span><\/span><\/code><\/pre>\n<p>\u8981\u4e86\u89e3\u6709\u5173\u6dfb\u52a0\u7684\u6587\u4ef6\u7684\u66f4\u591a\u4fe1\u606f<code>docker init<\/code>\uff0c\u8bf7\u53c2\u9605\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<ul>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u5728\u76ee\u5f55\u5185<code>python-docker<\/code>\uff0c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose up --build <\/span><\/span><\/code><\/pre>\n<p>\u67e5\u770b\u5e94\u7528\u7a0b\u5e8f \u3002\u60a8\u5e94\u8be5\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684 Flask \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u6309<code>ctrl<\/code>+<code>c<\/code>\u505c\u6b62\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3><\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u9009\u9879\u6765\u8fd0\u884c\u4e0e\u7ec8\u7aef\u5206\u79bb\u7684\u5e94\u7528\u7a0b\u5e8f<code>-d<\/code> \u3002\u5728\u76ee\u5f55\u5185<code>python-docker<\/code>\uff0c\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose up --build -d <\/span><\/span><\/code><\/pre>\n<p>\u67e5\u770b\u5e94\u7528\u7a0b\u5e8f \u3002<\/p>\n<p>\u60a8\u5e94\u8be5\u770b\u5230\u4e00\u4e2a\u7b80\u5355\u7684 Flask \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u505c\u6b62\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p><span> <\/span><br \/>\n<span> <\/span> <\/p>\n<pre><code><span><span><span>$<\/span> docker compose down <\/span><\/span><\/code><\/pre>\n<p>\u6709\u5173 Compose \u547d\u4ee4\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 \u3002<\/p>\n<h2><\/h2>\n<p>\u5728\u672c\u90e8\u5206\u4e2d\uff0c\u60a8\u4e86\u89e3\u4e86\u5982\u4f55\u4f7f\u7528 Docker \u5bb9\u5668\u5316\u548c\u8fd0\u884c Python \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<h2><\/h2>\n<p>\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u5bb9\u5668\u5f00\u53d1\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06 Python \u5e94\u7528\u7a0b\u5e8f\u5bb9\u5668\u5316 \u60a8\u5df2\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 \u3002 \u4f60\u6709\u4e00\u4e2a \u3002\u672c\u8282\u4e2d\u7684\u793a\u4f8b\u4f7f\u7528\u57fa\u4e8e\u547d\u4ee4\u884c\u7684 git \u5ba2\u6237\u7aef\uff0c\u4f46\u60a8\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5ba2\u6237\u7aef\u3002 \u672c\u90e8\u5206\u5c06\u5f15\u5bfc\u60a8\u5b8c\u6210\u5bb9\u5668\u5316\u548c\u8fd0\u884c Python \u5e94\u7528\u7a0b\u5e8f\u3002 \u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u6d41\u884c\u7684 \u6846\u67b6\u3002 \u514b\u9686\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u4ee5\u4e0e\u672c\u6307\u5357\u4e00\u8d77\u4f7f\u7528\u3002\u6253\u5f00\u7ec8\u7aef\uff0c\u5c06\u76ee\u5f55\u66f4\u6539\u4e3a\u60a8\u60f3\u8981\u5de5\u4f5c\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u514b\u9686\u5b58\u50a8\u5e93\uff1a $ git clone https:\/\/github.com\/docker\/python-docker \u73b0\u5728\u60a8\u5df2\u7ecf\u6709\u4e86\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u60a8\u53ef\u4ee5\u7528\u6765docker init\u521b\u5efa\u5fc5\u8981\u7684 Docker \u8d44\u4ea7\u6765\u5bb9\u5668\u5316\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u76ee\u5f55\u4e2d python-docker\uff0c\u8fd0\u884cdocker init\u547d\u4ee4\u3002docker init\u63d0\u4f9b\u4e86\u4e00\u4e9b\u9ed8\u8ba4\u914d\u7f6e\uff0c\u4f46\u60a8\u9700\u8981\u56de\u7b54\u4e00\u4e9b\u6709\u5173\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u8fd9\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528Flask\u6765\u8fd0\u884c\u3002\u8bf7\u53c2\u9605\u4ee5\u4e0b\u793a\u4f8b\u6765\u56de\u7b54\u63d0\u793a\uff0cdocker init\u5e76\u5bf9\u63d0\u793a\u4f7f\u7528\u76f8\u540c\u7684\u7b54\u6848\u3002 $ docker init Welcome to the Docker Init CLI! This utility will walk you through creating the following files with sensible defaults for your project: &#8211; .dockerignore &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-4225","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4225","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=4225"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/4225\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=4225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=4225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=4225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}