RAG/Dockerfile

62 lines
2.2 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.

# RAG API Dockerfile
# 构建包含所有依赖的 RAG RESTful 服务镜像
FROM python:3.13-slim
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
NLTK_DATA=/app/nltk_data/
# 配置国内 apt 镜像源(加速包下载)
# 使用阿里云 Debian 镜像源(适用于 Debian/Ubuntu 系统)
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list 2>/dev/null || \
(echo "deb https://mirrors.aliyun.com/debian/ bookworm main" > /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main" >> /etc/apt/sources.list && \
echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list)
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*
# 配置 pip 镜像源(加速 Python 包安装)
RUN pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/ && \
pip config set install.trusted-host mirrors.aliyun.com
# 复制依赖文件
COPY requirements.txt /app/
# 安装 Python 依赖
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# 复制项目文件
COPY . /app/
# 创建必要的目录
RUN mkdir -p /app/chroma_db /app/logs /app/static/swagger-ui
# 可选:如果在构建时有网络连接,可以下载 Swagger UI 资源
# 取消下面的注释以在构建时自动下载资源(需要网络连接)
# RUN python download_swagger_assets.py || echo "Warning: Failed to download Swagger UI assets. Run download_swagger_assets.py manually if needed."
# 暴露端口(注意:使用 host 网络模式时EXPOSE 仅作文档说明)
EXPOSE 8001
# 健康检查(注意:使用 host 网络模式时,健康检查由 docker-compose.yml 配置)
# HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
# CMD curl -f http://localhost:8001/health || exit 1
# 启动命令
CMD ["python", "main.py"]