Dockerfile 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # syntax=docker/dockerfile:1
  2. FROM python:3.12-slim
  3. # 替换为阿里云 apt 源(Debian 12 使用 DEB822 格式)
  4. RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
  5. sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources
  6. # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
  7. # 使用 cache mount 缓存 apt 包,避免每次重新下载
  8. RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
  9. --mount=type=cache,target=/var/lib/apt,sharing=locked \
  10. apt-get update && apt-get install -y \
  11. # OpenCV 核心依赖
  12. libgl1 \
  13. libglib2.0-0 \
  14. libsm6 \
  15. libxext6 \
  16. libxrender1 \
  17. # X11 库(OpenCV 需要)
  18. libxcb1 \
  19. libxcb-shm0 \
  20. libxcb-icccm4 \
  21. libxcb-image0 \
  22. libxcb-keysyms1 \
  23. libxcb-randr0 \
  24. libxcb-render-util0 \
  25. libxcb-render0 \
  26. libxcb-shape0 \
  27. libxcb-sync1 \
  28. libxcb-xfixes0 \
  29. libxcb-xinerama0 \
  30. libxcb-xkb1 \
  31. libxkbcommon-x11-0 \
  32. # 其他可能需要的库
  33. libfontconfig1 \
  34. libfreetype6 \
  35. # LibreOffice(用于 docx/doc 转 PDF)
  36. libreoffice-writer \
  37. libreoffice-core \
  38. # 中文字体(PDF 转换中文支持)
  39. fonts-wqy-zenhei \
  40. --no-install-recommends
  41. ENV DEBIAN_FRONTEND=noninteractive \
  42. TZ=Asia/Shanghai
  43. # 安装系统依赖包并创建虚拟环境
  44. RUN chmod 777 /tmp \
  45. && python -m venv /venv
  46. ENV PATH="/venv/bin:$PATH"
  47. # 先复制 requirements 文件安装依赖(利用缓存)
  48. COPY requirements.txt /tmp/
  49. # 使用 cache mount 缓存 pip 包,避免大依赖(torch/scipy 等)每次重新下载
  50. RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
  51. /venv/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
  52. && /venv/bin/pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn \
  53. && /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt
  54. # 设置工作目录并复制项目文件
  55. WORKDIR /app
  56. COPY . /app
  57. EXPOSE 8001
  58. # 确保脚本可执行
  59. RUN chmod 777 run.sh
  60. # 使用虚拟环境运行脚本
  61. #CMD ["/venv/bin/gunicorn", "-c", "gunicorn_config.py", "server.app:app"]
  62. # 带参数的启动方式
  63. CMD ["/venv/bin/python", "server/app.py", "--host", "0.0.0.0", "--port", "8001"]