-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
# 第一阶段:构建/安装 | ||
FROM python:3.9 AS builder | ||
|
||
ENV APP /app | ||
WORKDIR $APP | ||
# 使用Python 3.9和Alpine作为基础镜像 | ||
FROM python:3.9-alpine | ||
|
||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple | ||
# 设置环境变量 | ||
ENV APP=/app | ||
|
||
COPY . . | ||
# 创建应用目录 | ||
RUN mkdir $APP | ||
WORKDIR $APP | ||
|
||
# 第二阶段:生产环境镜像 | ||
FROM python:3.9-alpine | ||
# 暴露Gunicorn监听的端口 | ||
EXPOSE 5000 | ||
|
||
ENV APP /app | ||
WORKDIR $APP | ||
# 将requirements.txt文件复制到容器内 | ||
COPY requirements.txt . | ||
|
||
# 安装gunicorn、gevent及其依赖 | ||
RUN apk add --update --no-cache gcc libc-dev libffi-dev && \ | ||
pip install --no-cache-dir gunicorn gevent | ||
# 安装必要的依赖包,包括gunicorn、gevent、flask、pycrypto和pybase64 | ||
# 需要安装额外的编译工具以便在Alpine上正确构建某些依赖(如gevent) | ||
RUN apk add --no-cache build-base libffi-dev musl-dev && \ | ||
pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple | ||
|
||
COPY --from=builder $APP . | ||
# 复制项目源码到容器内 | ||
COPY . . | ||
|
||
EXPOSE 5000 | ||
# 设置默认启动命令为运行Gunicorn,并指定配置文件 | ||
CMD ["gunicorn", "start:app", "-c", "./gunicorn.conf.py"] |