Lesson 13 of 30
Not a virtual machine — a way to package an app with everything it needs to run, so 'works on my machine' stops being a real category of bug.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 2
A Dockerfile copies the entire source tree, then runs pnpm install. Every build re-runs the slow install step, even for a one-line CSS change. Why?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
A container packages your app's code together with its exact runtime environment — the Node version, installed dependencies, OS-level libraries — into one portable unit. Unlike a full virtual machine, containers share the host machine's OS kernel, which makes them dramatically lighter and faster to start.
FROM node:20-alpine
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
CMD ["pnpm", "start"]
Each line is a layer. Docker caches layers — if package.json hasn't changed since the last build, the pnpm install layer is reused from cache instead of re-run, which is exactly why COPY package.json happens before COPY . .: dependency installs (slow, changes rarely) get cached independently from source code (fast, changes constantly).
Dockerfile: FROM node:20; COPY .; RUN npm install; CMD npm start — a recipe for building an image.
pnpm install, even for a one-line CSS tweak.build stage with the full toolchain (compilers, dev dependencies) produces the built output, and a separate final stage copies only that output into a minimal runtime image, discarding everything else.Frontend roles increasingly touch containerized deployment, and "why is our Docker build so slow" is a genuinely common real question — correctly diagnosing it as a layer-caching/ordering issue is a concrete, practical signal beyond just knowing docker run exists.