Files
recommend/Dockerfile

56 lines
1.8 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 && \
python -m pip install --force-reinstall gunicorn && \
python -c "import gunicorn; print(f'Gunicorn version: {gunicorn.__version__}')" && \
python -m gunicorn --version || echo "Gunicorn installed, using python -m gunicorn"
# 复制应用代码
COPY . .
# 创建必要的目录
RUN mkdir -p templates static/css static/js logs data models
# 设置权限
RUN chmod +x start_web.py
# 暴露端口
2025-11-05 13:32:14 +08:00
EXPOSE 7400
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
2025-11-05 13:32:14 +08:00
CMD python -c "import requests; requests.get('http://localhost:7400/health')" || exit 1
# 使用gunicorn启动应用生产环境
2025-11-03 12:29:32 +08:00
# 注意默认配置使用2个worker适合1GB+内存的机器
# 如果机器内存较小512MB-1GB建议修改为 "--workers", "1"
# 使用 python -m gunicorn 确保可以找到 gunicorn即使可执行文件不在PATH中也能工作
2025-11-05 13:32:14 +08:00
CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:7400", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "web_app:app"]