{"id":205493,"date":"2020-11-26T03:10:26","date_gmt":"2020-11-25T19:10:26","guid":{"rendered":"http:\/\/4563.org\/?p=205493"},"modified":"2020-11-26T20:05:28","modified_gmt":"2020-11-26T12:05:28","slug":"%e8%ae%bf%e9%97%ae%e4%b8%8d%e5%88%b0%e8%bf%90%e8%a1%8c%e5%9c%a8-docker-%e9%87%8c%e9%9d%a2%e7%9a%84-flask-%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=205493","title":{"rendered":"\u8bbf\u95ee\u4e0d\u5230\u8fd0\u884c\u5728 docker \u91cc\u9762\u7684 flask \u5e94\u7528"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bbf\u95ee\u4e0d\u5230\u8fd0\u884c\u5728 docker \u91cc\u9762\u7684 flask \u5e94\u7528               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>server.py \u7684\u5173\u952e\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code>if __name__ == '__main__':     app.run(host='0.0.0.0', port=9000) <\/code><\/pre>\n<p>Dockerfile \u5982\u4e0b\uff1a<\/p>\n<pre><code>FROM python:3.7-buster  WORKDIR \/app\/  COPY .\/requirements.txt \/app\/requirements.txt RUN pip3 install -r requirements.txt -i https:\/\/mirrors.aliyun.com\/pypi\/simple\/  COPY . \/app\/  EXPOSE 9000 ENV FLASK_APP=server.py CMD python -m flask run --host=0.0.0.0 -p 9000 <\/code><\/pre>\n<p>\u4e0b\u9762\u8fd9\u6837\u5b50\u53ef\u4ee5\u8bbf\u95ee\u5230 localhost:9000 \u3002<\/p>\n<pre><code>docker container run --name user-info-pool-service -d -p 9000:9000 user-info-pool-service <\/code><\/pre>\n<p>\u4f46\u662f\u4e0b\u9762\u8fd9\u6837\u5374\u4e0d\u884c\u3002<\/p>\n<pre><code>docker container run --network=host --name user-info-pool-service -d user-info-pool-service <\/code><\/pre>\n<p>\u771f\u7684\u597d\u5947\u602a\uff0c\u4e3a\u4ec0\u4e48\u5462\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4321979\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dilu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u54e5\uff0c\u4f60\u7b2c\u4e8c\u4e2d\u65b9\u6cd5\u6ca1\u6709\u6620\u5c04\u7aef\u53e3\u554a&#8230;&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321980\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kosmosr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e86\u89e3\u4e00\u4e0b-p \u53c2\u6570\u4f60\u5c31\u77e5\u9053\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321981\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u7684\u8fd9\u4e24\u6761\u5bb9\u5668\u8fd0\u884c\u547d\u4ee4\u90fd\u662f\u53ef\u4ee5\u7684\u3002<br \/>\u6211\u6309\u4f60\u7684 scenario \u6d4b\u8bd5\u4e86\u4e00\u4e0b\uff0c\u53ea\u8981\u5220\u9664\u6389 server.py \u4e2d\u7684 main \u90e8\u5206\u5c31\u53ef\u4ee5\u4e86\uff0c\u5927\u6982\u662f\u8fd9\u90e8\u5206\u542f\u52a8\u548c CMD \u4e2d\u7684\u542f\u52a8\u547d\u4ee4\u51b2\u7a81\u4e86\u3002\u6211\u7684 server.py \u5982\u4e0b\uff0c\u5176\u4ed6\u7684\u548c\u4f60\u4e00\u6837\uff1a<\/p>\n<p>from flask import Flask<br \/>app = Flask(__name__)<\/p>\n<p>@app.route(&#8216;\/&#8217;)<br \/>def hello_world():<br \/> return &#8216;Hello, World!&#8217;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321982\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dilu <br \/>@kosmosr <\/p>\n<p>Docker \u5728 host \u6a21\u5f0f\u4e0b\u662f\u4f1a\u76f4\u63a5\u8fd0\u884c\u5728\u5bbf\u4e3b\u673a\u7f51\u7edc\u73af\u5883\u4e2d\u7684\uff0c\u6b64\u65f6\u5c31\u4e0d\u9700\u8981\u6620\u5c04\u7aef\u53e3\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321983\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : taolu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8211;network host \u53ea\u9002\u7528\u4e8e Linux\uff0c\u4e0d\u652f\u6301 win \u548c mac                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321984\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : acmore <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @taolu \u5bf9\u7684\uff0c\u8fd8\u6709\u53ef\u80fd\u662f\u8fd9\u79cd\u60c5\u51b5\u3002<\/p>\n<p>&#8220;The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.&#8221;                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321985\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kosmosr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @acmore \u5b66\u4e60\u5230\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321986\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JasonLaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @taolu #5 <br \/>@acmore #6 <\/p>\n<p>\u6211\u8bb0\u8d77\u6765\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4321987\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : taolu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JasonLaw #8 \u6211\u4e5f\u662f\u4e4b\u524d\u8e29\u8fc7\u5751\u624d\u8bb0\u5f97 <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/11\/9kZ3y873-48.png\" alt=\"\u8bbf\u95ee\u4e0d\u5230\u8fd0\u884c\u5728 docker \u91cc\u9762\u7684 flask \u5e94\u7528\"> <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbf\u95ee\u4e0d\u5230\u8fd0\u884c\u5728 docker \u91cc\u9762&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/205493"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=205493"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/205493\/revisions"}],"predecessor-version":[{"id":205498,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/205493\/revisions\/205498"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=205493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=205493"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=205493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}