docker部署django项目( 包含负载均衡)

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

作者:piggthird

出处:https://www.cnblogs.com/piggthird/p/17844471.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   PiggThird  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu