FROM python:3.11-slim-bullseye # 1. 安装基础工具 USER root RUN apt-get update && apt-get install -y \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/* RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # 2. 升级 pip RUN pip install --no-cache-dir --upgrade pip # 3. 分两步安装,确保 llama-cpp-python 命中预编译库 COPY --chown=user ./requirements.txt requirements.txt # 先安装除了 llama 以外的依赖(减少编译冲突风险) RUN pip install --no-cache-dir \ torch \ transformers \ gradio \ accelerate \ --extra-index-url https://download.pytorch.org/whl/cpu # 关键:从 abetlen 的 CPU 专用源安装 llama-cpp-python RUN pip install --no-cache-dir \ llama-cpp-python \ --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu COPY --chown=user . /app CMD ["python", "app.py"]