# 使用基础的 Python 镜像 FROM python:3.8-slim # 安装必要的系统库 RUN apt-get update && apt-get install -y \ build-essential \ libatlas-base-dev \ git \ curl \ && rm -rf /var/lib/apt/lists/* # 设置缓存目录并使用 HF_HOME 环境变量(推荐使用 HF_HOME) ENV HF_HOME=/tmp/huggingface_cache # 创建缓存目录并设置权限 RUN mkdir -p /tmp/huggingface_cache && chmod -R 777 /tmp/huggingface_cache # 创建并进入工作目录 WORKDIR /app # 安装依赖 RUN pip install --upgrade pip RUN pip install torch transformers peft datasets accelerate bitsandbytes huggingface_hub gradio # 将代码和数据复制到容器中 COPY . /app # 运行训练脚本 CMD ["python", "train.py"]