[uwsgi]
#使用nginx连接时使用,真实ip,端口不能占用已使用端口
socket=0.0.0.0:8001
#直接做web服务器使用
#http=172.xx.xx.xx:8001
#项目目录
chdir=/DjangoProTest
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=DjangoProTest/wsgi.py
processes=4
threads=2
master=True
pidfile=uwsgi.pid
;daemonize=uwsgi.log
注: 最后的daemonize应该注释掉,否则docker容器启动后便会立即停止,docker容器需要一个持续运行的前台进程,否则会终止容器运行
# syntax=docker/dockerfile:1
FROM python:3.8-slim-buster
WORKDIR /DjangoProTest
COPY requirement.txt requirement.txt
RUN apt-get update
RUN apt-get install -y gcc
RUN pip3 install -r requirement.txt
RUN pip3 install uwsgi
COPY . .
CMD ["uwsgi", "--ini", "uwsgi.ini"]
version: '3.8'
services:
django_server:
build:
context: .
image: django_server_image:v1.0.0
# command: uwsgi --ini uwsgi.ini
volumes:
- ./:/DjangoProTest
container_name: django_server_project
restart: always
ports:
- 8001:8001
networks: #定义该容器的网桥名称和IP地址
net-django:
ipv4_address: 10.127.2.5
nginx:
restart: always
image: nginx
volumes:
- ./deploy_conf/nginx/nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
- 8000:8000
networks: #定义该容器的网桥名称和IP地址
net-django: # 全局网桥名称
ipv4_address: 10.127.2.4
networks: #定义整个docker-compose编排的容器使用的网桥名称和IP地址网段,注意 x.x.x.1不能使用
net-django:
ipam:
config:
- subnet: 10.127.2.0/24 # ip地址网段
user root;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
## 后端
server {
listen 8000;
server_name localhost; # localhost就行,当访问8000端口会自动映射过来
location / {
# 配置路径
include uwsgi_params;
uwsgi_pass 10.127.2.5:8001; # 项目容器的ip和uwsgi开放的端口
}
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
docker-compose -f Docker-compose.dev.yml up --build -d