The Docker build takes a long time because:
- Flash-attention compilation - Takes 10-30+ minutes to compile from source
- IndexTTS cloning - Clones the entire repository each time
- Layer invalidation - Code changes invalidate expensive compilation steps
-
Layer reordering - Stable dependencies (flash-attention, IndexTTS) are installed BEFORE code copying
- Code changes no longer invalidate expensive compilation
- Only wrapper code changes trigger fast reinstall
-
Docker layer caching - Each layer is cached independently
- If only
indextts_fastapi/api.pychanges, flash-attention won't recompile
- If only
Enable BuildKit for even better caching:
# Enable BuildKit (one-time setup)
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# Or add to ~/.docker/config.json
{
"features": {
"buildkit": true
}
}Then rebuild:
docker-compose build --progress=plain- Flash-attention compilation: ~15-30 minutes (cached after first build)
- IndexTTS installation: ~2-5 minutes (cached unless repo changes)
- Wrapper dependencies: ~30 seconds (cached unless pyproject.toml changes)
- Code copying: <1 second
Full rebuild happens when:
- Dockerfile changes (especially early layers)
- Base image changes
- IndexTTS repo URL changes
- Python version changes
- Build dependencies change
Partial rebuild (fast) happens when:
- Only wrapper code changes (
indextts_fastapi/) - Only
pyproject.tomlchanges - Only
docker-compose.ymlchanges (no rebuild needed, just restart)
- Use
--no-cachesparingly - Only when you suspect cache issues - Keep Dockerfile stable - Put frequently changing files at the end
- Use multi-stage builds - Already implemented for minimal final image
- Consider pre-built wheels - Flash-attention wheels exist but may not match CUDA version