docker部署django项目
在你项目路径下:requirement.txt,Dockerfile,uwsgi.ini

Dockerfile
FROM python:3.6
MAINTAINER tiger
EXPOSE 8080
ADD ./requirement.txt /home/
RUN pip install -r /home/requirement.txt -i https://pypi.douban.com/simple/
RUN pip install uwsgi -i https://pypi.douban.com/simple/
VOLUME ["/home"]
WORKDIR /home/django_test
#CMD ["uwsgi", "--ini", "/home/django_test/uwsgi.ini"]
CMD ["python", "/home/django_test/manage.py", "runserver", "0.0.0.0:8080"]
uwsgi.ini
[uwsgi]
;socket=0.0.0.0:8080
http=0.0.0.0:8080
chdir=/home/django_test/
wsgi-file=django_test/wsgi.py
processes=4
threads=2
master=True
pidfile=uwsgi.pid
流程
# 1 代码写完,提交到git上
# 2 部署测试环境/真实环境---远程连接到服务器
# 3 git clone https://gitee.com/piggthird/django_test.git
# 4 基于Dockerfile制作镜像
docker build -t='django_207' . # 打包创建镜像名字随便取
# 运行容器
docker run -di --name=mydjango -v /root/tg/django_test/:/home/django_test/ -p 8080:8080 django_207
# 配置nginx转发
# 创建文件夹
mkdir -p /opt/nginx/conf /opt/nginx/html /opt/nginx/logs
# 新建配置文件
vim /opt/nginx/conf/nginx.conf
# 写入 配置负载均衡 修改nginx配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream node {
server 10.0.0.100:8080;
server 10.0.0.100:8081;
server 10.0.0.100:8082;
}
server {
listen 80;
server_name localhost;
location / {
#proxy_pass http://10.0.0.100:8080;
#负载均衡配置
proxy_pass http://node;
}
}
}
# docker 中运行nginx
docker run --name nginx -id -p 80:80 -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/nginx/html:/etc/nginx/html -v /opt/nginx/logs:/var/log/nginx nginx