Dockerfile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. FROM python:3.12-slim
  2. # 安装 OpenCV 系统依赖(更完整的列表)
  3. RUN apt-get update && apt-get install -y \
  4. # OpenCV 核心依赖
  5. libgl1 \
  6. libglib2.0-0 \
  7. libsm6 \
  8. libxext6 \
  9. libxrender1 \
  10. # X11 库(OpenCV 需要)
  11. libxcb1 \
  12. libxcb-shm0 \
  13. libxcb-icccm4 \
  14. libxcb-image0 \
  15. libxcb-keysyms1 \
  16. libxcb-randr0 \
  17. libxcb-render-util0 \
  18. libxcb-render0 \
  19. libxcb-shape0 \
  20. libxcb-sync1 \
  21. libxcb-xfixes0 \
  22. libxcb-xinerama0 \
  23. libxcb-xkb1 \
  24. libxkbcommon-x11-0 \
  25. # 其他可能需要的库
  26. libfontconfig1 \
  27. libfreetype6 \
  28. && rm -rf /var/lib/apt/lists/*
  29. ENV DEBIAN_FRONTEND=noninteractive \
  30. TZ=Asia/Shanghai
  31. # 安装系统依赖包并创建虚拟环境
  32. RUN chmod 777 /tmp \
  33. && python -m venv /venv
  34. ENV PATH="/venv/bin:$PATH"
  35. # 先复制 requirements 文件安装依赖(利用缓存)
  36. COPY requirements.txt /tmp/
  37. RUN /venv/bin/pip config set global.index-url https://mirrors.aliyun.com/pypi/simple \
  38. && /venv/bin/pip config set install.trusted-host mirrors.aliyun.com \
  39. && /venv/bin/pip --default-timeout=1800 install -r /tmp/requirements.txt \
  40. && rm -rf /root/.cache
  41. # 设置工作目录并复制项目文件
  42. WORKDIR /app
  43. COPY . /app
  44. EXPOSE 8001
  45. # 确保脚本可执行
  46. RUN chmod 777 run.sh
  47. # 使用虚拟环境运行脚本
  48. #CMD ["/venv/bin/gunicorn", "-c", "gunicorn_config.py", "server.app:app"]
  49. # 带参数的启动方式
  50. CMD ["/venv/bin/python", "server/app.py", "--host", "0.0.0.0", "--port", "8001"]