Files
mchat/faiss/Dockerfile
2026-04-10 11:55:00 +00:00

48 lines
1.1 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Dockerfile
FROM python:3.12-slim AS builder
# 设置环境变量
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# 安装系统依赖faiss-cpu 编译需要)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libopenblas-dev \
libomp-dev \
&& rm -rf /var/lib/apt/lists/*
# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# 最终镜像
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# 运行时需要的系统库
RUN apt-get update && apt-get install -y --no-install-recommends \
libopenblas-dev \
libomp-dev \
&& rm -rf /var/lib/apt/lists/*
# 从 builder 复制已安装的 Python 包
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# 复制项目代码
COPY . .
# 暴露端口
EXPOSE 8000
# 启动命令(使用字符串路径,兼容 reload
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]