{"id":153223,"date":"2020-09-08T07:52:02","date_gmt":"2020-09-07T23:52:02","guid":{"rendered":"http:\/\/4563.org\/?p=153223"},"modified":"2020-09-08T07:52:02","modified_gmt":"2020-09-07T23:52:02","slug":"docker-compose-up-%e9%87%8d%e6%96%b0%e6%9e%84%e5%bb%ba%e4%b8%8d%e6%9b%b4%e6%96%b0%e4%bb%a3%e7%a0%81%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=153223","title":{"rendered":"docker-compose up \u91cd\u65b0\u6784\u5efa\u4e0d\u66f4\u65b0\u4ee3\u7801\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  docker-compose up \u91cd\u65b0\u6784\u5efa\u4e0d\u66f4\u65b0\u4ee3\u7801\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u95ee\u9898\u662f\u8fd9\u6837\u7684\uff0c\u6211\u7528\u4e86 docker-compose \u6253\u5305\u4e00\u4e2a Django Web \u9879\u76ee\uff0c\u5206\u4e3a\u4e24\u4e2a\u5bb9\u5668\uff1anginx \u548c django(\u5305\u542b uWSGI \u548c django)\uff0c\u7b2c\u4e00\u6b21\u4f7f\u7528\u547d\u4ee4<code>docker-compose up<\/code>\u5c06\u9879\u76ee\u6784\u5efa\u597d\u8dd1\u8d77\u6765\u4e86\uff0c\u540e\u6765\u91cd\u65b0\u4fee\u6539\u4e86\u4e00\u4e0b uWSGI \u7684\u914d\u7f6e\u6587\u4ef6 uwsgi.ini, \u6539\u4e86\u4e00\u4e9b\u5176\u4e2d\u7684\u914d\u7f6e\uff0c\u4e5f\u4fee\u6539\u4e86\u4e00\u4e9b Django \u9879\u76ee\u4e2d\u7684 Python \u4ee3\u7801\uff0c\u7136\u540e\u6267\u884c<code>docker-compose build<\/code>\u548c<code>docker-compose up<\/code>\u91cd\u65b0\u6784\u5efa\uff0c\u4f46\u662f\u6784\u5efa\u5b8c\u4e86\u4e4b\u540e\u8fd0\u884c\u8fd8\u662f\u8001\u6837\u5b50\uff0c\u548c\u7b2c\u4e00\u6b21\u6784\u5efa\u8d77\u6765\u7684\u7a0b\u5e8f\u4e00\u6837\uff0c\u6ca1\u6709\u53d1\u751f\u4efb\u4f55\u4fee\u6539\u3002 \u4f7f\u7528<code>docker exec -it bash<\/code>\u8fdb\u5165 django \u5bb9\u5668\u4e4b\u540e\u53d1\u73b0 uwsgi.ini \u548c\u4fee\u6539\u8fc7\u7684 python \u4ee3\u7801<strong>\u90fd\u6ca1\u6709\u6539\u53d8<\/strong>\uff0c\u53cd\u590d\u5c1d\u8bd5\u8fc7\u4e86\u4e0b\u9762\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>\u5220\u9664 docker \u4e2d\u6240\u6709\u76f8\u5173\u7684\u5bb9\u5668\u3001\u955c\u50cf\uff0c\u91cd\u65b0\u6784\u5efa\uff0c\u8fd8\u662f\u65e0\u6548\uff0c\u4ee3\u7801\u548c\u914d\u7f6e\u6587\u4ef6\u8fd8\u662f\u6ca1\u53d8<\/li>\n<li>\u4f7f\u7528<code>docker-compose build --no-cache<\/code>\u91cd\u65b0\u6784\u5efa\uff0c\u8fd8\u662f\u6ca1\u53d8<\/li>\n<li>\u4f7f\u7528<code>docker system prune -a<\/code>\u5220\u9664\u6240\u6709 docker \u955c\u50cf\u4e4b\u540e\u518d\u91cd\u65b0\u6784\u5efa\uff0c\u8fd8\u662f\u6ca1\u53d8<\/li>\n<li>\u4f7f\u7528<code>docker-compose up --force-recreate<\/code>\u91cd\u65b0\u6784\u5efa\uff0c\u8fd8\u662f\u6ca1\u53d8<\/li>\n<\/ul>\n<p>\u6298\u817e\u4e86\u4e00\u4e2a\u665a\u4e0a\uff0c\u771f\u7684\u662f\u8981\u54ed\u4e86\u3002 \u9644\u4e0a\u6211\u7684\u4e24\u4e2a Dockerfile \u548c docker-compose.yml:<\/p>\n<pre><code>version: '3' services:      nginx:         container_name: nginx-container         build: .\/nginx         restart: always         ports:             - \"80:80\"             - \"8080:8080\"         volumes:             - .\/nginx_log:\/var\/log\/nginx             - shared_data:\/django_project         depends_on:             - django         privileged: true           networks:                net-django:                 ipv4_address: 10.127.2.3      django:         container_name: django-container         build: .\/django_project         restart: always         command: uwsgi --ini uwsgi_conf.ini         ports:             - \"8111:8111\"         volumes:             - .\/uwsgi_log:\/django_project\/logs             - shared_data:\/django_project         privileged: true           networks:                net-django:                 ipv4_address: 10.127.2.2 volumes:     shared_data:   networks:     net-django:     ipam:       config:         - subnet: 10.127.2.0\/24 <\/code><\/pre>\n<p>django \u7684 Dockerfile:<\/p>\n<pre><code>FROM python:3 ENV PYTHONUNBUFFERED 1 ENV DJANGO_SECRET_KEY xxx RUN mkdir \/django_project WORKDIR \/django_project ADD . \/django_project RUN pip3 install -i https:\/\/pypi.tuna.tsinghua.edu.cn\/simple -r requirements.txt EXPOSE 8111 <\/code><\/pre>\n<p>nginx \u7684 Dockerfile<\/p>\n<pre><code>FROM nginx:latest  COPY nginx.conf \/etc\/nginx\/nginx.conf COPY django_nginx.conf \/etc\/nginx\/sites-available\/  RUN mkdir -p \/etc\/nginx\/sites-enabled\/     &amp;&amp; ln -s \/etc\/nginx\/sites-available\/django_nginx.conf \/etc\/nginx\/sites-enabled\/  CMD [\"nginx\", \"-g\", \"daemon off;\"] <\/code><\/pre>\n<p>\u6309\u7406\u8bf4\u91cd\u65b0\u6784\u5efa\u7684\u8bdd\u4f1a\u5c06\u4fee\u6539\u8fc7\u7684\u4ee3\u7801\u548c\u914d\u7f6e\u6587\u4ef6\u901a\u8fc7<code>ADD . \/django_project<\/code>\u91cd\u65b0\u653e\u5165\u5bb9\u5668\u554a\uff0c\u4e3a\u4ec0\u4e48\u5c31\u662f\u4e0d\u53d8\u5462\uff1f \u6709\u5927\u4f6c\u8d50\u6559\u5417\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3217932\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Ariver <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5e76\u4e0d\u4f1a build                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217933\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lzk50136 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8211;build                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217934\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nvkou <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u811a\u672c\u578b\u4ee3\u7801\u53ef\u4ee5\u4e0d\u653e\u5bb9\u5668\u91cc\uff0c\u6620\u5c04\u4e3b\u673a\u76ee\u5f55\u5373\u53ef\u3002\u7701\u4e86 build \u3002\u5982\u679c\u6709 ci \u5f53\u6211\u6ca1\u8bf4                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217935\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : djFFFFF <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u90a3\u4e48\u591a\u65b9\u6cd5\u8fd8\u662f\u6ca1\u53d8\uff0c\u8bf4\u660e\u8be5\u6539\u53d8\u601d\u8def\u4e86\uff0c\u4e0d\u662f\u56e0\u4e3a\u6ca1\u8bc6\u522b\u5230\u4fee\u6539\uff0c\u662f\u56e0\u4e3a\u5c31\u662f\u6ca1\u6709\u4fee\u6539\u3002\u4f60\u5e94\u8be5\u770b\u4e00\u770b\u4e3a\u4ec0\u4e48\u6ca1\u6709\u4fee\u6539\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217936\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : freevioce <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4fee\u6539\u5b8c\u5efa\u8bae\u5728 build \u7684\u65f6\u5019\u770b\u4e0b\u5728\u8d70 Dockerfile \u5173\u952e\u884c\u6709\u6ca1\u6709\u8d70 cache\uff0c\u6309\u7406\u8bf4\u52a0\u4e0a&#8211;no-cache \u4f1a\u4ece\u5934 build \u3002\u3002\u3002\u5bf9\u4e86\u4f60\u6253\u5f00\u5173\u95ed\u7f16\u8f91\u5668\u770b\u770b\u4f60\u4fee\u6539\u6587\u4ef6\u751f\u6548\u4e86\u6ca1\uff0c\u81ea\u5df1\u8c03\u8bd5\u7684\u8bdd\u5efa\u8bae\u628a\u6574\u4e2a\u9879\u76ee\u90fd\u6302\u8f7d\u51fa\u53bb                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217937\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Ariver \u90a3\u600e\u4e48\u6837\u624d\u80fd\u591f\u8ba9\u5b83\u91cd\u65b0 Build?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217938\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lzk50136 \u8bd5\u8fc7`docker-compose up -d &#8211;build`\u4e86\uff0c\u4e5f\u4e0d\u884c\u3002\u3002\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217939\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @freevioce \u6587\u4ef6\u4ee3\u7801\u786e\u8ba4\u662f\u4fdd\u5b58\u4fee\u6539\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217940\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shingle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             docker-compose restart                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217941\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u89e3\u51b3\u4e86\uff0c\u65b0\u5efa\u4e86\u65b0\u7684\u6587\u4ef6\u5939\uff0c\u66f4\u6539\u4e86 Dockerfile \u4e2d\u7684\u9879\u76ee\u8def\u5f84\uff0c\u91cd\u65b0 build\uff0c\u73b0\u5728\u53ef\u4ee5\u4e86\u3002<br \/>\u8fd9\u6b21\u6784\u5efa\u7684\u65f6\u5019\u591a\u4e86\u4e00\u884c\u201cCreating volume &#8220;docker-deployment-1_shared_data&#8221; with default driver\u201d\uff0c\u6211\u60f3\u95ee\u9898\u5e94\u8be5\u662f\u51fa\u5728 shared_data \u8fd9\u4e2a Volume \u4e0a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217942\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kylinsun <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5\u901a\u8fc7 ADD \u7684\u65b9\u5f0f\u5728\u4f60\u7684 Dockerfile \u4e2d\u628a\u914d\u7f6e\u6587\u4ef6\u6dfb\u52a0\u5230\u5bf9\u5e94\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8fdb\u884c docker-compose &#8216;\u4f60\u7684\u5bb9\u5668&#8217; build \u8bd5\u8bd5\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217943\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : danshendog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f04\u660e\u767d\u4e86\uff0c\u662f\u56e0\u4e3a\u5171\u4eab\u5377\u5728\u5bbf\u4e3b\u673a\u8fd8\u7559\u6709\u7f13\u5b58\u7684\u539f\u56e0\uff0c\u5176\u5b9e\u6bcf\u6b21\u6784\u5efa\u5b8c\u4e86\u5982\u679c\u53d1\u73b0\u4e0d\u5bf9\u5e94\u8be5\u4f7f\u7528`docker-compose down -v`\u5728\u505c\u6b62\u5bb9\u5668\u548c\u7684\u540c\u65f6\u5220\u9664\u751f\u6210\u7684\u5171\u4eab\u5377\uff0c\u6216\u8005\u901a\u8fc7`docker volume ls`\u67e5\u770b\u5e76\u5220\u9664\u5197\u4f59\u7684\u5377\u3002<br \/>\u5220\u9664\u5b8c\u6bd5\u4e4b\u540e\u518d\u4f7f\u7528`docker-compose up`\u6784\u5efa\u8d77\u6765\u7684\u955c\u50cf\u5c31\u662f\u6700\u65b0\u7684\u4e86\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3217944\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Aixiaoa <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @danshendog \u6211\u6700\u8fd1\u4e5f\u662f\u53d1\u73b0<br \/>\u5982\u679c\u4fee\u6539\u4e86 yml\uff0c\u5355\u7eaf\u7684 up \u662f\u6ca1\u6709\u7528\u7684\u3002\u5b83\u663e\u793a up to data<br \/>\u4f46\u662f\u5b9e\u9645\u9700\u8981\u5148 down \u518d up \u624d\u4f1a\u91cd\u65b0\u8d77\u5bb9\u5668                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>docker-compose up&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\/153223"}],"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=153223"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/153223\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=153223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=153223"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=153223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}