111105 / Dockerfile
snsbhg's picture
Update Dockerfile
26310e0 verified
# 使用官方 PyTorch 镜像作为基础
FROM pytorch/pytorch:2.3.1-cuda11.8-cudnn8-runtime
# 切换到 root 用户以安装系统依赖
USER root
# 设置环境变量
ENV PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_PREFER_BINARY=1 \
NUMBA_CACHE_DIR=/tmp/numba_cache
# 设置工作目录
WORKDIR /app
# 安装系统依赖
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ffmpeg libsox-dev git \
build-essential cmake ninja-build pkg-config && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /tmp/numba_cache && chmod -R 777 /tmp/numba_cache
# [双重保障-步骤1] 预先创建 /nltk_data 目录并赋予 777 权限
RUN mkdir -p /nltk_data && chmod 777 /nltk_data
# 克隆 GPT-SoVITS 仓库
RUN git clone --depth 1 https://github.com/RVC-Boss/GPT-SoVITS.git /app
# 安装 Python 依赖
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r /app/requirements.txt && \
pip install --no-cache-dir --force-reinstall numpy==1.23.5 librosa==0.9.2 numba==0.56.4 && \
pip install --no-cache-dir fastapi uvicorn soundfile huggingface_hub ffmpeg-python
# [双重保障-步骤2 / 关键修复]
# 在构建镜像时,预先下载好 NLTK 所需的所有数据包,包括新发现的 "averaged_perceptron_tagger_eng"
RUN python -c "import nltk; nltk.download('punkt', quiet=True, download_dir='/nltk_data'); nltk.download('averaged_perceptron_tagger', quiet=True, download_dir='/nltk_data'); nltk.download('averaged_perceptron_tagger_eng', quiet=True, download_dir='/nltk_data')"
# 预下载依赖模型
COPY download_support_models.py /app/download_support_models.py
RUN python /app/download_support_models.py || true
# 复制您自己的权重文件和参考音频
COPY weights/ /app/pretrained_models/shantianliang/
COPY reference_audio/ /app/reference_audio/
# 更改 /app 目录所有权,赋予运行时用户写入权限
RUN chown -R 1000:1000 /app
# 暴露 API 端口
EXPOSE 7860
# 容器启动命令
CMD ["python", "api_v2.py", "-a", "0.0.0.0", "-p", "7860", "-c", "GPT_SoVITS/configs/tts_infer.yaml"]