Files
flask_rulebase_serve/Dockerfile
2026-04-22 13:35:40 +08:00

44 lines
1023 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 多阶段构建:减小最终镜像体积
FROM python:3.11
# 设置工作目录
WORKDIR /app
# 复制依赖文件
COPY requirements.txt .
# 安装运行时依赖
RUN pip install -r requirements.txt -i https://mirrors.cloud.tencent.com/pypi/simple/
# 复制应用代码
COPY . .
# 配置应用目录结构
RUN mkdir -p /app/__pycache__ /app/logs
# 配置时区
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
# 端口配置(默认生产 5222可用于本地测试 5228
ARG APP_PORT=5222
ENV APP_PORT=$APP_PORT
# 暴露Gunicorn监听的端口对外提供服务
EXPOSE ${APP_PORT}
# 环境变量配置
# ENV FLASK_APP="app:app" \
# FLASK_ENV="production" \
ENV PYTHONUNBUFFERED=1 \
PATH="/venv/bin:$PATH"
# Gunicorn启动命令核心配置
CMD ["sh", "-c", "gunicorn \
--bind 0.0.0.0:${APP_PORT} \
--workers 14 \
--timeout 60 \
--keep-alive 5 \
--access-logfile - \
--error-logfile - \
run:app"]