Interview Prep/Python for DevOps/Environments, imports & packaging errors

Your Docker build reinstalls all Python dependencies on every code change, taking 4 minutes.

BeginnerTroubleshootingEnvironments, imports & packaging errors
Answer

Likely causes → COPY . . happens before pip install, so any source change invalidates the install layer cache.

Diagnose → Read the Dockerfile order; docker build --progress=plain shows which step starts missing cache.

Fix →

COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
COPY src/ ./src/

Prevent → Copy dependency manifests first, source last; use BuildKit cache mounts.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, imports & packaging errors