Containers with Docker

Intermediate 15 min read

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

  1. Plan & Design
  2. Develop
  3. Version control
  4. Verify
  5. Build & Package
  6. CI/CD
  7. ● Deploy › Servers & containers
  8. Operate

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

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.

Dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
USER node
EXPOSE 3000
CMD ["node", "server.js"]
Example
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

Guides

Reference

Learn next

Done with this topic?

Reviewed 2026-10-23. Links go to the official documentation unless marked otherwise.