Skip to content

Commit

Permalink
Update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeo-hub authored Jan 31, 2024
1 parent 077669b commit 41d4206
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions Dockerfile
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"]

0 comments on commit 41d4206

Please sign in to comment.