# GPU-Accelerated Kokoro TTS Dockerfile FROM nvidia/cuda:12.1.1-runtime-ubuntu22.04 # Environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ HF_HOME=/root/.cache/huggingface \ PORT=8880 \ DEFAULT_VOICE=af_heart \ DEBIAN_FRONTEND=noninteractive # Install Python 3.10 and system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ python3.10 \ python3.10-dev \ python3-pip \ espeak-ng \ ffmpeg \ libsndfile1 \ curl \ git \ && rm -rf /var/lib/apt/lists/* \ && ln -s /usr/bin/python3.10 /usr/bin/python WORKDIR /app # Copy requirements and install python packages with CUDA PyTorch COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cu121 && \ pip install --no-cache-dir -r requirements.txt # Pre-download default weights into cache RUN python -c "from kokoro import KPipeline; KPipeline(lang_code='a')" # Copy application code COPY app/ /app/app/ EXPOSE 8880 HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:${PORT}/health || exit 1 CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"]