Interview Prep/Docker/Image design and Dockerfile decisions

Your Docker build re-installs all Python dependencies on every code change. Fix it.

BeginnerScenarioImage design and Dockerfile decisions
Answer

Situation read → COPY . . comes before pip install, so any file change busts the cache.

What I'd do →

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .

Add a .dockerignore so irrelevant changes (.git, __pycache__) do not invalidate COPY . . either.

Why → Layers are cached top-down; order from least to most frequently changing.

Interview tip → State the rule: "dependencies manifest first, source last."

All Docker questions Roadmap: Docker & containers

More on Image design and Dockerfile decisions