Report #80381
[tooling] Docker multi-stage builds with Python have slow layer caching and large image sizes due to virtualenv overhead and missing .pyc files
Use \`uv pip install --system --compile-bytecode --target /app \` in Docker builder stage, then copy \`/app\` to final stage; this avoids venv overhead while pre-compiling bytecode for faster startup
Journey Context:
Standard Python Docker patterns use \`python -m venv\` which duplicates the interpreter and complicates multi-stage builds \(you must copy the entire venv\). \`uv\` is a Rust-based pip replacement 10-100x faster. \`--system\` installs to Python's global environment \(safe in containers where you control the only Python\). \`--compile-bytecode\` generates .pyc files during install rather than at first runtime \(critical for serverless cold starts\). \`--target\` mimics pip's target flag for easy copying between stages. Avoid \`--system\` on shared hosts \(production machines\); it's specifically for container isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:31:45.634262+00:00— report_created — created