优化docker

This commit is contained in:
赵杰 Jie Zhao (雄狮汽车科技)
2025-11-03 13:19:49 +08:00
parent ed5f32016d
commit 6fc4438a13

View File

@@ -25,8 +25,10 @@ RUN apt-get update && apt-get install -y \
COPY requirements.txt .
# 安装Python依赖排除GUI相关依赖Docker中不需要
RUN pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir gunicorn
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
pip install --no-cache-dir gunicorn && \
which gunicorn || echo "Gunicorn installed via python -m"
# 复制应用代码
COPY . .
@@ -47,4 +49,5 @@ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
# 使用gunicorn启动应用生产环境
# 注意默认配置使用2个worker适合1GB+内存的机器
# 如果机器内存较小512MB-1GB建议修改为 "--workers", "1"
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"]
# 使用 python -m gunicorn 确保可以找到 gunicorn
CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"]