优化: Docker 环境下的下载性能和网络稳定性

- Chromium 启动参数优化:禁用 dev-shm 和 GPU 加速,防止Docker内存不足
- 增加所有超时时间:login/navigate/export 超时 30s,下载超时 300s
- 改进网络延迟处理:增加数据加载等待时间,添加网络加载检测
- Docker Compose 资源配置:限制 2 CPU / 2GB 内存,DNS 配置国际公共 DNS
- Dockerfile 优化:添加 PYTHONHASHSEED 环境变量,跳过浏览器下载校验
- 新增 docker-debug.sh 脚本:便捷测试 Docker 容器中的下载功能
- 新增 .dockerignore:加速 Docker 构建,减少镜像大小

Docker 下载现在支持更长的网络延迟和更大的数据量
This commit is contained in:
2026-05-17 16:09:55 +08:00
parent 505e5ca895
commit 975f9e5887
6 changed files with 183 additions and 19 deletions
+7 -3
View File
@@ -9,8 +9,10 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1
# 确保 Python 输出不被缓冲
ENV PYTHONUNBUFFERED=1
# 禁用 Python 的硬件指令集检查,提高Chromium兼容性
ENV PYTHONHASHSEED=0
# 安装 Playwright 所需的系统依赖
# 安装 Playwright 所需的系统依赖 + 网络优化
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
ca-certificates \
@@ -29,6 +31,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libxdamage1 \
libxrandr2 \
xdg-utils \
dnsmasq \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖文件
@@ -38,8 +41,8 @@ COPY requirements.txt .
# 使用阿里云镜像源加速
RUN pip install --no-cache-dir -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 安装 Playwright Chromium 浏览器
RUN playwright install --with-deps chromium
# 安装 Playwright Chromium 浏览器(增加超时以处理网络不稳定)
RUN PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0 playwright install --with-deps chromium
# 复制当前目录内容到容器中的 /app
COPY . .
@@ -50,5 +53,6 @@ RUN mkdir -p uploads data downloads && chmod 777 uploads data downloads
# 暴露端口 5000
EXPOSE 5000
# 增加容器内存限制和进程管理
# 运行 app.py
CMD ["python", "app.py"]