-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
46 lines (36 loc) · 1.65 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# syntax=docker/dockerfile:1
FROM python:3.7-slim-buster
RUN mkdir /deploy
# 设置工作目录(后续都不需要指定完整路径了,默认工作目录/deploy)
WORKDIR /deploy
# 复制源码 (使用映射代替copy)
#COPY ./app ./deploy/app
# 复制发布相关脚本
COPY requirements.txt requirements.txt
COPY gunicorn.conf.py gunicorn.conf.py
# 安装依赖
RUN pip3 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip3 install gunicorn -i https://pypi.tuna.tsinghua.edu.cn/simple
RUN pip3 install gevent -i https://pypi.tuna.tsinghua.edu.cn/simple
# 更新apt源
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN apt-get update && apt-get install -y nginx supervisor
# 配置nginx
RUN rm /etc/nginx/sites-enabled/default
COPY nginx_flask.conf /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-available/nginx_flask.conf /etc/nginx/sites-enabled/nginx_flask.conf
# 是否后台启动:决定启动nginx命令是否block,因为supervisor不能监控后台进程,command 不能为后台运行命令
# 用supervisor启动nginx的话需要关掉daemon
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# supervisord https://www.jianshu.com/p/0b9054b33db3
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 复制运行脚本
COPY ./script/run.sh ./run.sh
RUN chmod +x ./run.sh
# 设置环境变量(给flask迁移db用)
ENV FLASK_APP="app:create_app('production')"
ENV FLASK_ENV="production"
# 运行(最后这条CMD命令需要阻塞,否则docker启动后接着退出)
CMD ["./run.sh"]