Django+uwsgi 容器部署過程

1. 準備pip.conf

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

2. requirements.txt加上uwsgi

Django == 3.1.7
djangorestframework == 3.12.2
markdown == 3.3.4
django-filter == 2.4.0
psycopg2-binary == 2.8.6
uwsgi == 2.0.19.1

3. uwsgi.ini

[uwsgi]
http = 0.0.0.0:8080 #http方便測試,生產部署需要修改爲socket
# plugins = python3
dir=/var/www/escort/escort
pythonpath=/var/www/escort
master = true
module = escort.wsgi:application
processes = 4
enable-threads = true
buffer-size = 8192
chmod-socket=666
max-request=2000
wsgi-file=/var/www/escort/escort/wsgi.py

4. Dockerfile

FROM python:3.8


MAINTAINER Hayden


RUN apt update

RUN apt -y install uwsgi-plugin-python3


RUN mkdir -p /var/www/escort

COPY pip.conf /root/.pip/pip.conf


WORKDIR /var/www/escort


ADD . .

RUN pip install -r requirements.txt

EXPOSE 8080
CMD [ "bash", "start.sh" ]

5. start.sh

python manage.py makemigrations&&
python manage.py migrate&&
uwsgi --ini /var/www/escort/uwsgi.ini

5. 構建和本地進入測試

docker build -t escort:0.1.2 .

docker run -it -p 8080:8080   escort:0.1.2 bash

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章