{"id":50742,"date":"2020-12-21T20:23:28","date_gmt":"2020-12-21T12:23:28","guid":{"rendered":"http:\/\/www.zhushiyao.com\/?p=50742"},"modified":"2020-12-21T20:24:04","modified_gmt":"2020-12-21T12:24:04","slug":"a27c4eb5f0","status":"publish","type":"post","link":"http:\/\/www.zhushiyao.com\/?p=50742","title":{"rendered":"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09"},"content":{"rendered":"<div class=\"bpp-post-content\">\n<p>\u4e0a\u4e00\u671f\u6211\u4eec\u8bb2\u5230\u4e86\u5728\u81ea\u5df1\u7684\u672c\u673a\u4e0a\u8fd0\u884c\u6211\u4eec\u7684\u6a21\u578b\u53ca\u7f51\u9875\u6f14\u793a\uff0c\u8fd9\u671f\u6211\u4eec\u5c06\u5982\u4f55\u5c06\u6211\u4eec\u505a\u597d\u7684application\u90e8\u7f72\u5230\u522b\u7684\u5730\u65b9\u3002<\/p>\n<p>\u6211\u4eec\u7528\u5230\u7684\u5de5\u5177\u53eb Docker<\/p>\n<h2><b>\u4e00\u3001docker\u4ecb\u7ecd<\/b><\/h2>\n<p>Docker \u662f\u4e00\u79cd\u4f7f\u7528\u5bb9\u6613\u90e8\u7f72\u548c\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u5de5\u5e8f\u3002\u5bb9\u5668\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5c06\u5e94\u7528\u7cfb\u7edf\u548c\u6240\u9700\u7684\u6240\u6709\u90e8\u5206\uff08\u5982\u5e93\u548c\u5176\u4ed6\u4f9d\u8d56\u9879\uff09\u6253\u5305\u5728\u4e00\u8d77\uff0c\u5e76\u5c06\u5176\u5168\u90e8\u6253\u5305\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u5305\u3002\u8fd9\u6837\uff0c\u501f\u52a9\u5bb9\u5668\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u653e\u5fc3\u5c06\u8be5\u5e94\u7528\u7a0b\u5e8f\u8fd0\u884c\u5728\u4efb\u4f55\u5176\u4ed6linux\u673a\u5668\u4e0a\uff0c\u800c\u4e0d\u7528\u7ba1\u8be5\u673a\u5668\u7684\u81ea\u5b9a\u4e49\u8bbe\u7f6e\u3002<\/p>\n<p>\u67d0\u79cd\u7a0b\u5ea6\u4e0a\uff0cDocker\u6709\u70b9\u50cf\u865a\u62df\u673a\u3002\u4f46\u662f\uff0c\u4e0e\u865a\u62df\u673a\u4e0d\u901a\uff0cDocker\u65e0\u9700\u521b\u5efa\u6574\u4e2a\u865a\u62df\u64cd\u4f5c\u7cfb\u7edf\uff0c\u800c\u662f\u5141\u8bb8\u5e94\u7528\u7cfb\u7edf\u4f7f\u7528\u4e0e\u5176\u6240\u8fd0\u884c\u7684\u7cfb\u7edf\u76f8\u540c\u7684Linux\u5185\u6838\u3002\u8fd9\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u6027\u80fd\u5e76\u51cf\u5c11\u5e94\u7528\u7cfb\u7edf\u7684\u5927\u5c0f\u3002<\/p>\n<h2><b>\u4e8c\u3001\u5199 Dockerfile<\/b><\/h2>\n<figure><img decoding=\"async\" class=\"origin_image zh-lightbox-thumb\" title=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/12\/0-1608553408.jpeg\" alt=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" width=\"1080\" \/><\/figure>\n<p>\u5728\u4e4b\u524d\u7684\u5de5\u4f5c\u76ee\u5f55\u91cc\u5199Dockerfile\uff0c \u6ce8\u610f\u8fd9\u4e2a\u6587\u4ef6\u7684\u547d\u540d\u5c31\u53eb Dockerfile<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">#\u9009\u62e9\u7cfb\u7edf FROM ubuntu  #\u7ef4\u62a4\u4eba\u5458\u7684\u8054\u7cfb\u65b9\u5f0f MAINTAINER rl2987@columbia.edu  LABEL version=\"1.0\"  #\u8f93\u51fa\u7684\u7aef\u53e3 EXPOSE 8080  #\u7ed9docker\u4e2d\u6587\u73af\u5883 ENV LANG C.UTF-8  #\u66f4\u65b0ubuntu\u7cfb\u7edf\uff0c\u4e0b\u8f7d\u76f8\u5173\u7684dependency RUN apt-get update RUN apt-get install  libsm6 libxrender1 libxext-dev gcc -y  ##\u4e0b\u8f7dAnaconda3 python \u73af\u5883\u5b89\u88c5\u5305 \u653e\u7f6e\u5728\u7a0b\u5e8f\u76ee\u5f55 url\u5730\u5740https:\/\/repo.anaconda.com\/archive\/Anaconda3-2019.03-Linux-x86_64.sh  #docker\u5de5\u4f5c\u76ee\u5f55 WORKDIR  \/keras-docker  #\u5c06\u5f53\u524d\u76ee\u5f55\u4e0b\u7684\u5168\u90e8\u5185\u5bb9\u653e\u5165docker\u5de5\u4f5c\u76ee\u5f55 ADD . \/keras-docker  #\u5b89\u88c5anaconda RUN cd \/keras-docker &amp;&amp; sh -c '\/bin\/echo -e \"nyesnnyes\" | sh Anaconda3-2019.03-Linux-x86_64.sh'  #\u4e0b\u8f7dpython\u53ca\u9700\u8981\u7684\u5305 RUN echo -e \"ny\" | \/root\/anaconda3\/bin\/conda install python=3.6.7 RUN echo -e \"ny\" | \/root\/anaconda3\/bin\/conda install -c conda-forge scipy numpy==1.17.2 easydict cython h5py pandas requests beautifulsoup4 RUN echo -e \"ny\" | \/root\/anaconda3\/bin\/conda install -c conda-forge scikit-learn cheroot mahotas joblib RUN \/root\/anaconda3\/bin\/pip install tensorflow==1.13.2 keras==2.2.5 RUN \/root\/anaconda3\/bin\/pip install web.py==0.40.dev1 opencv-contrib-python==4.0.0.21 pillow==6.2.0  #\u5728docker\u4e2d\u5220\u9664anaconda\u7684\u5b89\u88c5\u6587\u4ef6 RUN rm Anaconda3-2019.03-Linux-x86_64.sh<\/code><\/pre>\n<\/div>\n<h2><b>\u4e09\u3001build image<\/b><\/h2>\n<p>\u8fd9\u90e8\u5206\u53ef\u4ee5\u5148\u770b\u89c6\u9891<\/p>\n<p><img decoding=\"async\" class=\"thumbnail\" title=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/12\/10-1608553408.jpeg\" alt=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" \/><span class=\"content\"><span class=\"title\">build docker image<\/span><span class=\"url\">https:\/\/www.zhihu.com\/video\/1181404051319881728<\/span><\/span><\/p>\n<h2><b>1\u3001build docker<\/b><\/h2>\n<figure><img decoding=\"async\" class=\"origin_image zh-lightbox-thumb\" title=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/12\/10-1608553409.jpeg\" alt=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" width=\"1080\" \/><\/figure>\n<p class=\"ztext-empty-paragraph\">\u00a0<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">docker build -t keras-docker:1.0 .<\/code><\/pre>\n<\/div>\n<p>\u6ce8\u610f\u6700\u540e\u7684\u90a3\u4e2a\u70b9\u662f\u7cbe\u9ad3,\u8868\u793a\u5728\u5f53\u524d\u6587\u4ef6\u5939\u521b\u5efadocker\uff0c \u7528\u5f53\u524d\u6587\u4ef6\u5939\u5185\u7684\u6587\u4ef6<\/p>\n<h2><b>2\u3001save image to tar file<\/b><\/h2>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">docker save -o keras-docker_1-0.tar keras_docker:1.0<\/code><\/pre>\n<\/div>\n<p>\u6ce8\u610f\u8fd9\u4e00\u6b65\u5f88\u6162\uff0c\u6211\u7b49\u4e86\u4e24\u5206\u591a\u949f\uff0c\u8bf7\u8010\u5fc3\u7b49\u5f85<\/p>\n<h2><b>\u56db\u3001\u5982\u4f55\u4f7f\u7528<\/b><\/h2>\n<p>\u540c\u6837\u5148\u770b\u89c6\u9891<\/p>\n<p><img decoding=\"async\" class=\"thumbnail\" title=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/12\/9-1608553409.jpeg\" alt=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" \/><span class=\"content\"><span class=\"title\">run docker image<\/span><span class=\"url\">https:\/\/www.zhihu.com\/video\/1181404182735802368<\/span><\/span><\/p>\n<h2><b>1\u3001\u6253\u5f00tar\u6587\u4ef6<\/b><\/h2>\n<figure><img decoding=\"async\" class=\"origin_image zh-lightbox-thumb\" title=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" src=\"http:\/\/www.zhushiyao.com\/wp-content\/uploads\/2020\/12\/8-1608553409.jpeg\" alt=\"\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\" width=\"1080\" \/><\/figure>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">docker run -p 8080:8080 keras_docker:1.0 \/root\/anaconda3\/bin\/python app.py<\/code><\/pre>\n<\/div>\n<p>\u8fd9\u4e2a\u53ef\u662f\u524d\u53f0\u8fd0\u884c\uff0c\u53ef\u4ee5\u770b\u5230\u90e8\u7f72\u7684\u60c5\u51b5<br \/>\u4e5f\u53ef\u4ee5\u540e\u53f0\u8fd0\u884c<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">docker run -d -p 8080:8080 keras_docker:1.0 \/root\/anaconda3\/bin\/python app.py<\/code><\/pre>\n<\/div>\n<p>\u7136\u540e\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">http:\/\/0.0.0.0:8080\/kind<\/code><\/pre>\n<\/div>\n<p>\u5c31\u53ef\u4ee5\u4f7f\u7528\u5566\uff01<\/p>\n<h2><b>\u4e94\u3001docker image \u7684\u4e0b\u8f7d\u5730\u5740<\/b><\/h2>\n<p>\u6211\u5df2\u7ecf\u4e0a\u4f20\u5230docker hub\u4e0a\uff0c\u76f4\u63a5\u4e0b\u8f7d\u5c31\u597d<\/p>\n<div class=\"highlight\">\n<pre><code class=\"language-text\">docker pull rachelliu\/keras_docker:1.0<\/code><\/pre>\n<\/div>\n<p>\u7ed3\u675f\u4e86\uff01<br \/>\u5927\u58f0\u56de\u7b54 \u7231\u4e0d\u7231\u6211\uff01<\/p>\n<p>\u9644\u4e0a\u671f\u6559\u7a0b\u5730\u5740\uff1a<\/p>\n<p>\u5982\u4f55\u7528web.py + docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u6539\uff09<\/p>\n<hr \/><\/div>\n\n\n<p>\u8f6c\u81ea\uff1ahttps:\/\/zhuanlan.zhihu.com\/p\/93252460<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0a\u4e00\u671f\u6211\u4eec\u8bb2\u5230\u4e86\u5728\u81ea\u5df1\u7684\u672c\u673a\u4e0a\u8fd0\u884c\u6211\u4eec\u7684\u6a21\u578b\u53ca\u7f51\u9875\u6f14\u793a\uff0c\u8fd9\u671f\u6211\u4eec\u5c06\u5982\u4f55\u5c06\u6211\u4eec\u505a\u597d\u7684application\u90e8\u7f72\u5230 &hellip; <a href=\"http:\/\/www.zhushiyao.com\/?p=50742\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5982\u4f55\u7528web.py+docker\u6765\u90e8\u7f72keras\u6a21\u578b\uff08\u4e8c\uff09\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[1005],"_links":{"self":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/50742"}],"collection":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50742"}],"version-history":[{"count":2,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/50742\/revisions"}],"predecessor-version":[{"id":50751,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=\/wp\/v2\/posts\/50742\/revisions\/50751"}],"wp:attachment":[{"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50742"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhushiyao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}