diff --git a/Dockerfile b/Dockerfile index 628ddf6..0f6f673 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,22 @@ -FROM mcr.microsoft.com/playwright/python:v1.58.0-jammy +FROM python:3.11-slim WORKDIR /app +# 设置环境变量,防止 Python 写 .pyc 文件,并强制无缓冲输出 +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt + +# 1. 安装 Python 依赖 +# 2. 仅安装 Chromium 浏览器 +# 3. 仅安装 Chromium 所需的系统级依赖 +# 4. 清理 apt 缓存,极致压缩镜像体积 +RUN pip install --no-cache-dir -r requirements.txt \ + && playwright install chromium \ + && playwright install-deps chromium \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /root/.cache/pip COPY main.py .