容器文件结构
作业顺序
生成images
[uwsgi]
project=training_system
base=/code/package
chdir=%(base)/%(project)
module=%(project).wsgi:application
master=True
processes=2
http=0.0.0.0:8000
buffer-size=65536
pidfile=/tmp/%(project)-master.pid
vacuum=True
max-requests=5000
daemonize=/tmp/%(project)-uwsgi.log
harakiri=60
harakiri-verbose=true
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
- start.sh 编写(其实也可以叫runserver-docker.sh之类的)
python manage.py collectstatic --noinput&&
python manage.py makemigrations&&
python manage.py migrate&&
uwsgi --ini uwsgi.ini
(uwsgi --ini uwsgi.ini有可能会报错,下面再解决这个问题)
- 修改dockfile不要直接启动应用,等容器启动后我们再手动启动应用
FROM python:3.8-slim
COPY ./Django /code
WORKDIR /code/package
RUN pip install -r requirements.txt
RUN chmod 777 /code/package/runserver-docker.sh
EXPOSE 8000
docker build -t training_dashboard_v2b_uwsgi .
进入容器安装uwsgi包
可参考我的文章【docker】如何在docker中安装uwsgi包
docker exec -it < container > /bin/bash
apt-get update
apt-get install gcc
pip install uwsgi
(可选)进入容器,手动实现uwsgi初始化
start.sh 中uwsgi --ini uwsgi.ini有可能会报错,故可进入容器,手动实现uwsgi初始化。
uwsgi --ini uwsgi.ini
uwsgi初始化成功显示[uWSGI] getting INI configuration from uwsgi.ini
参考链接
原创Docker部署Django由浅入深系列(上):单容器部署Django + Uwsgi
|