Files
AI-TianDong/Dockerfile
2025-07-24 12:45:27 +08:00

42 lines
1.6 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.

# 选择一个包含 Python 的基础镜像,考虑一个带编译工具的以防某些库需要编译
FROM nvidia/cuda:12.6.0-devel-ubuntu22.04
# 设置时区(可选,但对于日志时间戳有好处)
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 设置工作目录
WORKDIR /app
# 安装系统依赖(例如 OpenCV 可能需要)
# libgl1-mesa-glx 是常见的桌面OpenGL库对于 headless server 来说libgl1可能就够了
# 有些版本的OpenCV需要特定的共享库
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 libsm6 libxext6 libxrender-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# 安装 Python 和 pip
RUN apt-get update && apt-get install -y python3 python3-pip
ENV OMP_NUM_THREADS=1
# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# 复制整个应用代码和模型到容器中
COPY . .
# 确保模型目录存在且模型已复制 (Dockerfile中的COPY指令会处理此问题)
# 运行前检查模型路径是否正确:
# RUN ls -lR app/models/ # 这可以帮助你在构建时调试路径问题
# 暴露API服务运行的端口
EXPOSE 8000
# 容器启动时运行的命令
# 使用 --host 0.0.0.0 使服务可以从容器外部访问
# --reload 用于开发,生产中通常不使用
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]