Files
recommend/Dockerfile

54 lines
1.6 KiB
Docker
Raw Normal View History

# -*- coding: utf-8 -*-
# 使用Python 3官方镜像自动使用最新稳定版本匹配本机Python版本
FROM python:3-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
FLASK_APP=web_app.py \
FLASK_ENV=production
# 安装系统依赖用于OCR等功能
RUN apt-get update && apt-get install -y \
tesseract-ocr \
tesseract-ocr-chi-sim \
tesseract-ocr-eng \
2025-11-03 12:33:47 +08:00
libgl1 \
libglx-mesa0 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# 复制requirements文件
COPY requirements.txt .
# 安装Python依赖排除GUI相关依赖Docker中不需要
2025-11-03 13:19:49 +08:00
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 . .
# 创建必要的目录
RUN mkdir -p templates static/css static/js logs data models
# 设置权限
RUN chmod +x start_web.py
# 暴露端口
EXPOSE 5000
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:5000/health')" || exit 1
# 使用gunicorn启动应用生产环境
2025-11-03 12:29:32 +08:00
# 注意默认配置使用2个worker适合1GB+内存的机器
# 如果机器内存较小512MB-1GB建议修改为 "--workers", "1"
2025-11-03 13:19:49 +08:00
# 使用 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"]