提交
This commit is contained in:
43
Dockerfile
Normal file
43
Dockerfile
Normal file
@@ -0,0 +1,43 @@
|
||||
# 多阶段构建:减小最终镜像体积
|
||||
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"]
|
||||
Reference in New Issue
Block a user