{"id":435372,"date":"2021-04-18T16:20:52","date_gmt":"2021-04-18T08:20:52","guid":{"rendered":"http:\/\/4563.org\/?p=435372"},"modified":"2021-04-18T16:20:52","modified_gmt":"2021-04-18T08:20:52","slug":"python-%e5%ae%b9%e5%99%a8%e7%9a%84-dockerfile-%e4%b8%ba%e4%bb%80%e4%b9%88%e9%9c%80%e8%a6%81%e8%bf%99%e4%b8%80%e5%8f%a5-copy-requirements-txt","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=435372","title":{"rendered":"Python \u5bb9\u5668\u7684 Dockerfile \u4e3a\u4ec0\u4e48\u9700\u8981\u8fd9\u4e00\u53e5 &#8220;COPY requirements.txt .&#8221;"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u5bb9\u5668\u7684 Dockerfile \u4e3a\u4ec0\u4e48\u9700\u8981\u8fd9\u4e00\u53e5 &#8220;COPY requirements.txt .&#8221;               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : qwertyegg <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>FROM python:3.9.2-alpine3.12  WORKDIR \/usr\/src\/app  RUN pip install -r requirements.txt  CMD [ \"python\", \"api.py\" ] <\/code><\/pre>\n<p>\u6211\u5df2\u7ecf\u628a\u6587\u4ef6\u5939\u6620\u5c04\u5230 \/usr\/src\/app \u91cc\u9762\u4e86\uff0c\u6587\u4ef6\u5939\u5305\u542b\u4e86 requirements.txt(\u6240\u4ee5 \/usr\/src\/app \u91cc\u9762\u4e5f\u6709\u8fd9\u4e2a\u6587\u4ef6?)<\/p>\n<p>\u9519\u8bef\u63d0\u793a<\/p>\n<pre><code>ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' <\/code><\/pre>\n<p>\u4fee\u6539\u4e3a\u5b98\u65b9\u63a8\u8350\u7684<\/p>\n<pre><code>FROM python:3.9.2-alpine3.12  WORKDIR \/usr\/src\/app  COPY requirements.txt .  RUN pip install -r requirements.txt  CMD [ \"python\", \"api.py\" ] <\/code><\/pre>\n<p>\u5c31\u80fd\u6210\u529f build \u3002\u8bf7\u95ee\u4e3a\u4ec0\u4e48\u5728\u7b2c\u4e00\u79cd\u60c5\u51b5\u4e0b\u627e\u4e0d\u5230 requirements.txt<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5649312\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Phant0m <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u9ed8\u8ba4\u62c9\u53d6\u56de\u6765\u7684\u955c\u50cf\u5185\u662f\u6ca1\u6709 requirements.txt \u8fd9\u4e2a\u6587\u4ef6\u7684\uff0c\u955c\u50cf\u53ea\u5305\u542b\u5fc5\u8981\u7684\u8fd0\u884c\u73af\u5883\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5649313\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u201c\u628a\u6587\u4ef6\u5939\u6620\u5c04\u201d\u8fd9\u4e00\u6b65\u662f build \u6b65\u9aa4\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5649314\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : qwertyegg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @julyclyde \u6211\u662f\u7528\u7684 docker-compose \u6620\u5c04\u7684\u6587\u4ef6\u5939<\/p>\n<p>@Phant0m \u4e0d\u597d\u610f\u601d\uff0c\u6211\u6ca1\u8bf4\u6e05\u695a\u3002\u6211\u5728 docker-compose \u91cc\u9762\u5df2\u7ecf\u628a\u5305\u542b requirement.txt \u548c.py \u7684\u6587\u4ef6\u5939\u6620\u5c04\u5230 \/usr\/src\/app \u4e0b\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5649315\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @qwertyegg \u90a3\u4f60\u6620\u5c04\u8fc7\u4e4b\u540e RUN ls \u6216\u8005 RUN tree \u4e00\u4e0b\u770b\u770b\u91cc\u9762\u662f\u4ec0\u4e48\u6837\u5b50\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5649316\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : qwertyegg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @julyclyde \u8c22\u8c22\u4f60\u7684\u63d0\u793a\uff0c\u6211\u53bb\u8bd5\u4e00\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u5bb9\u5668\u7684 Docker&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\/435372"}],"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=435372"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/435372\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=435372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=435372"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=435372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}