FROM python:3.9-slim # 设置环境变量(国内镜像源加速下载) ENV PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple \ PIP_TRUSTED_HOST=pypi.tuna.tsinghua.edu.cn \ HF_ENDPOINT=https://hf-mirror.com WORKDIR /app # 先复制依赖文件(变化频率低) COPY requirements.txt . # 安装系统依赖并清理缓存(合并RUN指令减少层数) RUN apt-get update && \ apt-get install -y --no-install-recommends ffmpeg && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* # 安装Python依赖 RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # 最后复制应用代码(变化频率最高) COPY . . EXPOSE 7860 CMD ["python", "app.py"]