1. Base image
FROM picks the base image every later instruction builds on top of.
FROM node:22-alpineTyporithm · easy
Step 1 of 8 · intro card
Images
A Dockerfile declares how to build an image: FROM picks a base, WORKDIR sets the directory, COPY brings files in, RUN executes build steps, and CMD is the default process. Each instruction is a cached layer, so copy dependency manifests and install before the source to maximize cache hits.
A Dockerfile is a recipe for building an image. FROM chooses the base image, WORKDIR sets the directory commands run in, COPY brings files from your context into the image, and RUN executes build-time commands.
Every instruction produces a layer, and Docker caches layers. If an instruction and everything before it are unchanged, the cached layer is reused, so ordering matters for build speed.
Copying package*.json and running npm ci before COPY . . means the dependency layer only rebuilds when the manifests change, not on every source edit. CMD sets the default process the container runs.
FROM sets the base; CMD sets the default process.
Each instruction is a cached layer.
Copy manifests and install before the source.
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "server.js"]Connect each part of the code to the concept before you type.
FROM picks the base image every later instruction builds on top of.
FROM node:22-alpineWORKDIR sets the directory for the following COPY, RUN, and CMD instructions.
WORKDIR /appCopying just the package manifests first lets the install layer stay cached when only source changes.
COPY package*.json ./RUN executes a command during the build, here installing dependencies into a new layer.
RUN npm ciCMD declares the default command the container runs when it starts.
CMD ["node", "server.js"]Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.