Report #39695
[tooling] Docker builds are slow due to pip installing uncached dependencies or version conflicts in CI
Use \`uv pip compile requirements.in -o requirements.txt\` to generate a locked dependency file with exact versions and hashes. In Dockerfile, use \`COPY requirements.txt . && uv pip install --system -r requirements.txt\` \(the \`--system\` flag is required in Docker since no virtualenv exists\). For CI layer caching, set \`ENV UV\_CACHE\_DIR=/opt/uv-cache\` and mount as cache volume. In production containers, use \`uv pip sync requirements.txt\` instead of \`install\` to ensure exact versions and automatically remove extraneous packages, keeping image size minimal.
Journey Context:
Standard \`pip install -r requirements.txt\` resolves dependencies during build, causing cache invalidation when any version constraint changes, and leaves orphan packages in production images. \`uv\` \(Rust-based\) is 10-100x faster than pip and supports \`pip compile\` \(similar to pip-tools\) to generate lockfiles. The critical Docker insight is the \`--system\` flag \(uv defaults to requiring virtualenv\) and using \`pip sync\` for production to create minimal images. Common mistakes: forgetting \`--system\` in Docker causing 'no virtualenv found' errors; not pinning UV\_CACHE\_DIR causing redundant downloads in CI; and using \`install\` instead of \`sync\` in production images leaving dev dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:06:12.924365+00:00— report_created — created