系统相关
首页 > 系统相关> > Docker环境部署Django+Supervisor+Nginx

Docker环境部署Django+Supervisor+Nginx

作者:互联网

制作django镜像环境(Commit方式)

下载Ubuntu

$ docker pull ubuntu

运行并进入容器

$ docker container run -it ubuntu /bin/bash

下载python

/# apt-get install python3

如遇到下载问题如下图

 

 

 更新软件源,之后就可以正常下载python了

/# apt-get update

安装pip3工具

/# apt-get install python3-pip

修改pip下载的镜像源

/# apt-get install vim
/# mkdir ~/.pip
/# vim ~/.pip/pip.conf

[global]
index-url=http://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn

在pip.conf文件写入镜像地址

 

 

 安装Django相关库

/# pip3 install django
/# pip3 install pymysql
/# pip3 install uwsgi
/# pip3 install supervisor

制作镜像

$ docker commit -m='python3+django3' -a='zn' 6492bd45dd18 ubuntu:django1
docker-machine restart default

运行该容器并运行Django项目

$ docker container run -p 8083:8000 -it -v /web/:/home/project ubuntu:django1 /bin/bash

 

 

 浏览器访问网址 http://192.168.99.100:8083/admin 显示如下界面即为成功

开始尝试nginx部署

nginx 在一个docker里面,django+uwsgi在一个docker里面,nginx容器就直接从docker hub下载,Django镜像就用上面生成的ubuntu:django1镜像

$ docker pull nginx

准备配置文件,以挂载方式加载到容器中

Nginx配置文件 default.conf

upstream django{
         # server unix:///home/andrew/django/abuild/abulid.sock;
         server 192.168.99.100:8083;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name 192.168.99.100;
        charset utf-8;

        client_max_body_size 75M;


       location /media {
             alias /home/project/mysite/media;
       }

       location /static {
            alias /home/project/mysite/static;
       }

       location / {
           uwsgi_pass django;
           include /etc/nginx/uwsgi_params;

       }
}

supervisord.conf

利用supervisord.conf工具生成supervisord.conf初始文件

echo_supervisord_conf > /etc/supervisord.conf

然后在文件末尾添加以下内容,在保存到宿主机中

[program:mysite]
command=/usr/local/bin/uwsgi --ini /home/project/mysite/uwsgi.ini
directory=/home/project/mysite/
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true

uwsgi.ini

[uwsgi]
socket = :8000
chdir = /home/project/mysite/   
wsgi-file = mysite/wsgi.py
touch-reload = /home/project/mysite/reload

processes = 2
threads = 4

chmod-socket = 664
chown-socket = mysite:nginx

vacuum = true

py-autoreload=1

启动django镜像

/home/project/mysite# supervisorctl -c supervisord.conf restart mysite

 

标签:Supervisor,mysite,Django,project,Nginx,conf,home,docker,uwsgi
来源: https://www.cnblogs.com/tracydzf/p/15639726.html