docker部署django项目

为什么使用docker?

1,更高效的利用系统资源

2,可迁移性高

3,更快速的启动时间

4,一致的运行环境

开始部署:

apt install docker.io

在此之前你需要熟悉docket的基本用法

安装django镜像

docker search django

docker pull django

docker run --name django_uwsgi_nginx -p 80:80 -it django /bin/bash   

进入django容器

由于是ubuntu系统环境,可以先对系统更新

apt update  (嫌慢可以放上国内的源)

安装几个东西

apt install nginx    apt install git (如果你的django项目放在了git上,可以使用git clone下载)

apt install net-tools  (docker网络管理包  包括netstat 命令)

容器中的django是1.x版本的,需要更新到2.0版本的

pip3 uninstall django

pip3 install django

1,开始部署uwsgi

在django项目的根录目下 创建 ini文件 如 website.ini

写入:

socket          =127.0.0.1:9090   #9090连接nginx

chdir           = /root/website

module          =website.wsgi

master          = true

processes       = 4

vacuum          = true

尝试启动:

    uwsgi --ini website.ini

2,配置nginx

打开/etc/nginx/nginx.conf

在http代码块写入

server {
          listen 80;
          server_name xxxx(域名);
    
          location / {            #连接uwsgi
              uwsgi_pass 127.0.0.1:9090;  
              include uwsgi_params;
              uwsgi_param UWSGI_CHDIR /root/website;
              uwsgi_param UWSGI_SCRIPT website.wsgi;
          }

          location /static {
              alias /root/website/static;
          }
          access_log off;
      }

 开启服务:

uwsgi --ini website.ini & nginx

访问域名

猜你喜欢

转载自blog.csdn.net/wszsdsd/article/details/89242515