SkillByAIOpen interactive version →

Lesson 7 / 28

Dockerfile Basics

Write a Dockerfile with FROM, WORKDIR, COPY, RUN and CMD, and know build-time versus run-time instructions.

What is a Dockerfile?

A Dockerfile is a plain-text recipe of instructions that Docker follows, top to bottom, to build an image.

A minimal Node app

FROM sets the base image, COPY brings in your files, RUN executes build-time commands, and CMD sets the default startup command.

FROM node:22-alpine
WORKDIR /app
COPY package.json .
RUN npm ci
COPY . .
CMD ["node", "server.js"]

RUN vs CMD

RUN executes during the build and its result is baked into the image. CMD only runs when a container starts — one image can have many RUNs but usually just one CMD.