Card 06/ 07
All 7 cards
ExerciseDifficulty: Advanced1 min
Which Steps Rebuild?
Given this Dockerfile, work out what each change costs before you look.
FROM node:20-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
CMD ["node", "server.js"]You edit a comment in server.js. Which instructions run again?
COPY . . and CMD. The copy's layer changed, so everything after it reruns — but npm ci is above the copy and keeps its cache. CMD sets metadata and costs nothing.
You add a dependency to package.json. Which instructions run again?
COPY package.json package-lock.json ./ onwards, so the install as well. That is correct: the dependencies really did change.
You change FROM node:20-alpine to FROM node:22-alpine. Which instructions run again?
All of them. The first layer changed, so nothing below it has a cached layer to sit on.