| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- FROM python:3.12-slim
- # 替换为阿里云 apt 源(Debian 12 使用 DEB822 格式)
- RUN sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \
- sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources
- # 安装 OpenCV 系统依赖及 LibreOffice(docx/doc 转 PDF)
- RUN apt-get update && apt-get install -y \
- # OpenCV 核心依赖
- libgl1 \
- libglib2.0-0 \
- libsm6 \
- libxext6 \
- libxrender1 \
- # X11 库(OpenCV 需要)
- libxcb1 \
- libxcb-shm0 \
- libxcb-icccm4 \
- libxcb-image0 \
- libxcb-keysyms1 \
- libxcb-randr0 \
- libxcb-render-util0 \
- libxcb-render0 \
- libxcb-shape0 \
- libxcb-sync1 \
- libxcb-xfixes0 \
- libxcb-xinerama0 \
- libxcb-xkb1 \
- libxkbcommon-x11-0 \
- # 其他可能需要的库
- libfontconfig1 \
- libfreetype6 \
- # LibreOffice(用于 docx/doc 转 PDF)
- libreoffice-writer \
- libreoffice-core \
- # 中文字体(PDF 转换中文支持)
- fonts-wqy-zenhei \
- --no-install-recommends \
- && rm -rf /var/lib/apt/lists/*
- ENV DEBIAN_FRONTEND=noninteractive \
- TZ=Asia/Shanghai
- # 安装系统依赖包并创建虚拟环境
- RUN chmod 777 /tmp \
- && python -m venv /venv
- ENV PATH="/venv/bin:$PATH"
- # 先复制 requirements 文件安装依赖(利用缓存)
- COPY requirements.txt /tmp/
- RUN /venv/bin/pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
- && /venv/bin/pip config set install.trusted-host mirrors.aliyun.com \
- && /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt \
- && rm -rf /root/.cache
- # 设置工作目录并复制项目文件
- WORKDIR /app
- COPY . /app
- EXPOSE 8001
- # 确保脚本可执行
- RUN chmod 777 run.sh
- # 使用虚拟环境运行脚本
- #CMD ["/venv/bin/gunicorn", "-c", "gunicorn_config.py", "server.app:app"]
- # 带参数的启动方式
- CMD ["/venv/bin/python", "server/app.py", "--host", "0.0.0.0", "--port", "8001"]
|