Interview Prep/Real-World Interview/Write-a-Dockerfile tasks

Write a Dockerfile that uses BuildKit cache mounts to speed up package installs.

IntermediateHands-onWrite-a-Dockerfile tasks
Answer
# syntax=docker/dockerfile:1
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN --mount=type=cache,target=/root/.cache/pip \
    pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]

Key trick → A cache mount keeps the pip/npm/go cache between builds without storing it in the image. Even when the layer is invalidated, downloads come from the local cache.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Dockerfile tasks