Ess*_*eTi 5 nginx django uwsgi gunicorn docker
我无法理解部署使用 uwsgi/gunicorn 的 Django 项目的“正确”方法是什么(我还没有决定使用什么,可能是 uwsgi,因为它具有更好的性能和建议?)和 nginx 使用码头工人。
我看到有些人把所有东西都放在同一个容器里。我不是 docker 的专家,但容器应该只做一 (1) 件事。因此,拥有 Django + nginx 似乎是 2 而不是 1。
现在,我的部署想法是:
有没有其他方法可以做到?有没有更深入地介绍这种情况的教程。我需要一个可靠的产品,而不仅仅是在我的电脑上测试一些代码。
我目前正在按照您想要的方式构建 django 应用程序。
\n\n我使用 docker-compose 来做到这一点。这是我的 docker-compose.yml
\n\nversion: \'2\'\nservices:\n nginx:\n container_name: nginx-container\n links:\n - uwsgi\n build: ./nginx\n ports:\n - "8888:80"\n volumes_from:\n - uwsgi\n uwsgi:\n container_name: uwsgi-container\n build: ./uwsgi\n expose:\n - "8001"\n volumes:\n - ./code/conf:/opt/conf\n - ./code/app:/opt/app\n
Run Code Online (Sandbox Code Playgroud)\n\nuWSGI 的 Dockerfile:
\n\nFROM python:3.5\nRUN ["pip", "install", "uwsgi"]\nCMD ["uwsgi", "--master", "--ini", "/opt/conf/uwsgi.ini"]\n
Run Code Online (Sandbox Code Playgroud)\n\nnginx 的 Dockerfile:
\n\nFROM nginx\nRUN ["rm", "/etc/nginx/conf.d/default.conf"]\nRUN ["ln", "-s", "/opt/conf/nginx.conf", "/etc/nginx/conf.d/"]\nCMD ["nginx", "-g", "daemon off;"]\n
Run Code Online (Sandbox Code Playgroud)\n\n这是我的目录树:
\n\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 README.md\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 code\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 app\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 conf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 collectstatic.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 docker-compose.yml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 install.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 migrate.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 nginx\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dockerfile\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 restart.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 upgrade.sh\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 uwsgi\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Dockerfile\n
Run Code Online (Sandbox Code Playgroud)\n\n因此,我构建图像,docker-compose build
然后在后台启动新容器,docker-compose up -d
然后我可以执行一些设置任务,例如安装 django、生成密钥或任何您想要准备好容器的任务。
nginx 和 uwsgi 容器使用共享卷来读取配置文件并与文件套接字进行通信。
\n\n好吧,不确定这是最好的方法,但这是一项正在进行的工作。
\n 归档时间: |
|
查看次数: |
9271 次 |
最近记录: |