bge / Dockerfile
crgmail's picture
Update Dockerfile
e11947a verified
FROM python:3.10-slim
# HF Spaces 要求使用 7860 端口,非 root 用户
RUN useradd -m -u 1000 user
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# 先装 CPU 版 PyTorch(体积比 CUDA 版小 ~2GB)
RUN pip install --no-cache-dir \
torch==2.3.1+cpu \
--index-url https://download.pytorch.org/whl/cpu
# 安装其余依赖
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ✅ 构建阶段预下载模型,彻底避免运行时冷启动下载
# 模型文件烘焙进 Docker 镜像层
ENV HF_HOME=/app/hf_cache
RUN python -c "\
from huggingface_hub import snapshot_download; \
snapshot_download('BAAI/bge-m3', ignore_patterns=['*.msgpack','*.h5','flax_model*','tf_model*','rust_model*']); \
snapshot_download('BAAI/bge-reranker-v2-m3', ignore_patterns=['*.msgpack','*.h5','flax_model*','tf_model*','rust_model*']); \
print('Models downloaded successfully')"
RUN chown -R user:user /app/hf_cache
COPY --chown=user:user . .
USER user
EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]