Containers with Docker
Package an application with everything it needs into an image that runs the same on any machine.
Why it matters
Containers remove "works on my machine": the same image runs in development, CI and production. Most modern deployment platforms run containers.
Where it fits
What you will learn
- Explain the difference between an image and a container.
- Write a small Dockerfile and build it.
- Run several services together with Compose.
Before you start
- CI/CD pipelines✓ Learned
- Linux servers and SSH✓ Learned
Image and container
An image is a read-only package: an operating system layer, a runtime, your code and its dependencies. A container is a running instance of an image, isolated from the others. You build an image once and start as many containers from it as you need.
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
USER node
EXPOSE 3000
CMD ["node", "server.js"]
docker build -t my-app .
docker run --rm -p 3000:3000 my-app
Tip: Copy the dependency files and install before copying the rest of the code: Docker reuses the cached install layer when only your code changed.
Watch out: Do not bake secrets into an image — anyone who can pull it can read them. Pass them at runtime as environment variables or mounted secrets.
Install and set up
- Get Docker ↗ Docker Desktop for macOS and Windows, Docker Engine for Linux.
Official documentation and references
Documentation
- Docker Compose ↗ Official · Docker
Guides
- Docker — Get started ↗ Official · Docker
Reference
- Dockerfile reference ↗ Official · Docker
Learn next
- Nginx as a reverse proxy ›✓ Learned
Related topics
- Nginx as a reverse proxy✓ Learned
- Configuration and secrets✓ Learned
- CI/CD pipelines✓ Learned
Done with this topic?
Reviewed 2026-10-23. Links go to the official documentation unless marked otherwise.