From ceda9dd2e98816d34b6ca513ec95f1e00be9b6f5 Mon Sep 17 00:00:00 2001 From: liubo235 Date: Thu, 18 Dec 2025 11:40:50 +0800 Subject: [PATCH] build: Optimize Dockerfile with domestic mirrors - Switch APT sources to Aliyun mirrors for faster build speed in China - Switch PyPI source to Tsinghua mirrors - Add missing Playwright dependency steps --- Dockerfile | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36cb293..c5f3267 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,20 +3,25 @@ FROM python:3.11-slim # 设置工作目录 WORKDIR /app -# 安装系统依赖和 Playwright 依赖 +# 优化 1: 更换 APT 源为阿里云镜像 (针对 Debian Bookworm/Trixie) +RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \ + sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list + +# 安装系统依赖 RUN apt-get update && apt-get install -y \ wget \ gnupg \ && rm -rf /var/lib/apt/lists/* -# 复制项目文件 +# 复制依赖文件 COPY requirements.txt . -# 安装 Python 依赖 -RUN pip install --no-cache-dir -r requirements.txt +# 优化 2: 使用清华 PyPI 镜像安装 Python 依赖 +RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple # 安装 Playwright 浏览器和系统依赖 -# 注意:chromium 是必须的 +# 优化 3: Playwright 下载也可能慢,这取决于网络,通常很难加速, +# 但 install-deps 依赖 apt,上面换源后会快很多。 RUN playwright install chromium RUN playwright install-deps chromium @@ -32,6 +37,5 @@ RUN mkdir -p log # 暴露端口 EXPOSE 8000 50051 -# 启动命令 (默认启动 HTTP Server) +# 启动命令 CMD ["python", "http_server.py"] -