anisora / Dockerfile
kuanya's picture
Upload Dockerfile
30d7ef4 verified
# 使用带有CUDA的基础镜像
FROM nvcr.io/nvidia/pytorch:23.10-py3
# 设置环境变量(提前设置以利用Docker的层缓存)
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PYTHONPATH=/app \
HUGGINGFACE_HUB_CACHE=/app/cache \
HF_HOME=/app/cache \
HF_HUB_ENABLE_HF_TRANSFER=1 \
PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512 \
TORCH_CUDA_ARCH_LIST="7.5 8.0 8.6+PTX" \
FORCE_CUDA="1"
# 设置工作目录
WORKDIR /app
# 安装系统依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
libgl1-mesa-glx \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# 创建缓存目录
RUN mkdir -p /app/cache
# 复制项目文件(分步复制以利用Docker缓存)
COPY requirements.txt .
# 安装Python依赖(分步安装以利用缓存)
RUN pip install --no-cache-dir -U pip setuptools wheel && \
pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu118 && \
pip install --no-cache-dir xformers --index-url https://download.pytorch.org/whl/cu118
# 安装其他依赖
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY app.py .
# 暴露端口
EXPOSE 7860
# 健康检查
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860 || exit 1
# 启动命令
CMD ["python", "app.py"]