Report #75951
[bug\_fix] Dependency installation layer \(e.g., npm install, pip install\) rebuilds from scratch on every code change, taking 10\+ minutes
Copy only the dependency manifest files \(e.g., package.json and package-lock.json, or requirements.txt\) and run the install command before copying the rest of the source code.
Journey Context:
A developer notices CI builds are extremely slow. They check the logs and see 'Step 4/8 : RUN pip install -r requirements.txt' executing every time, even if dependencies haven't changed. They initially blame Docker cache or CI cache settings, spending hours tweaking --no-cache flags or CI cache volumes. Finally, they look at the Dockerfile order: they have COPY . /app followed by RUN pip install. Since COPY . /app includes all source code, any single line change in the app invalidates the cache for that layer and all subsequent layers. By splitting the copy into COPY requirements.txt . -> RUN pip install -> COPY . ., the heavy install step is cached unless requirements.txt changes, drastically reducing build times.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:04:45.099592+00:00— report_created — created