Loading earlier articles…

Docker Fundamentals — Containers That Ship

Images, containers, Dockerfiles, and the mental model that makes Docker click — with a real Node.js example.

10 min read

The Mental Model

A Dockerfile is a recipe. An image is the frozen meal. A container is the meal being eaten. Same recipe, unlimited identical meals — that is the whole point.

Your First Dockerfile

FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]

Build and Run

docker build -t my-app:1.0 .
docker run -d -p 3000:3000 --name my-app my-app:1.0

docker ps          # running containers
docker logs my-app # what is it saying?
docker exec -it my-app sh   # shell inside the container

The Rules That Save You Pain

  1. One process per container — no "everything" containers
  2. Never store data inside a container — use volumes
  3. Pin your base image versionsnode:20-alpine, not node:latest
  4. Order Dockerfile layers by change frequency — dependencies first, code last

Practice Task

Containerize any small app you have:

docker build -t practice-app .
docker run -p 8080:8080 practice-app

If it works on your machine, it now works on every machine. That is DevOps magic — see you in the next lesson.

Loading next article…