Lesson 7 / 26

Dockerfile Basics

FROM, COPY, RUN and CMD — the four instructions you'll use constantly.

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:20-alpine
WORKDIR /app
COPY package.json .
RUN npm install
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.