Dockerfile 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. FROM mcr.microsoft.com/playwright:v1.37.0-jammy
  2. # mcr.microsoft.com/playwright/python:v1.52.0
  3. # 设置非交互式环境变量和时区
  4. ENV DEBIAN_FRONTEND=noninteractive
  5. ENV TZ=Etc/UTC
  6. WORKDIR /app
  7. # 安装 Python 3.9 和 pip(修复时区阻塞问题)
  8. RUN sed -i 's|http://.*archive.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list && \
  9. sed -i 's|http://.*security.ubuntu.com|https://mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list && \
  10. apt-get update && \
  11. apt-get install -y software-properties-common tzdata python3 python3-pip ttf-wqy-microhei && \
  12. ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
  13. dpkg-reconfigure --frontend noninteractive tzdata && \
  14. add-apt-repository -y ppa:deadsnakes/ppa && \
  15. pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
  16. pip3 config set global.trusted-host pypi.tuna.tsinghua.edu.cn
  17. # 安装 Playwright Python 库和浏览器驱动
  18. RUN python3 -m pip install playwright && \
  19. python3 -m playwright install
  20. RUN pip install aiohttp toml pydantic fastapi sqlalchemy python-multipart uvicorn
  21. # 安装 Xvfb 和窗口管理器(支持有头模式)
  22. RUN apt-get install -y xvfb fluxbox && \
  23. rm -rf /var/lib/apt/lists/*
  24. # 设置环境变量
  25. ENV DISPLAY=:99
  26. COPY ./app /app
  27. # 启动脚本
  28. COPY entrypoint.sh /entrypoint.sh
  29. RUN chmod +x /entrypoint.sh
  30. ENTRYPOINT ["/entrypoint.sh"]