压缩镜像大小

This commit is contained in:
fuzhongyun 2026-03-31 09:04:58 +08:00
parent 243ce9c03c
commit 3d63eb4e96
1 changed files with 15 additions and 2 deletions

View File

@ -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 .