Package an application so it runs the same everywhere
A trail about containers for developers: images and Dockerfiles, the container lifecycle, data, networking and Docker Compose. Each lesson takes one command apart with an example and a common mistake, and at the end you build a compact production image.
- You write a Dockerfile with a clear build cache and a small final image
- You run, stop and debug containers without losing data
- You describe an application with a database in Docker Compose and set up networking between services
Why containers
What a container packages and how it differs from a virtual machine.
- “It works on my machine” — What exactly a container carries along with the program.
- A container is not a virtual machine — Why a container starts in a fraction of a second and what it shares with the host.
- Your first docker run — What happens at start and how to find a stopped container.
Images
Tags, layers, the Dockerfile and the build cache.
- Tags and layers — Why latest does not mean “fresh” and how images share disk space.
- The Dockerfile — Writing an image recipe and building it.
- The build cache — How the order of instructions saves minutes on every build.
Life of a container
Stopping, logs, getting inside and the start command.
- Stopping and restarting — How a container receives a signal and why it sometimes waits ten seconds.
- Logs and getting inside — Where to find the program's output and how to look at a container from the inside.
- CMD, ENTRYPOINT and PID 1 — How to set the start command so that signals reach the program.
Data
Where to keep what must outlive a container.
- The container layer is temporary — Why data disappears and where to keep it.
- Volumes and host folders — Named volumes, bind mounts and when to choose which.
- Backups and read-only mounts — How not to lose a volume and how to protect a config from writes.
Networking
Ports, networks between containers and what localhost means inside.
- Publishing ports — How to make a service in a container reachable from outside.
- Networks between containers — How containers find each other by name.
- localhost inside a container — Why localhost in a container is not your computer.
Docker Compose
Several services in one file: start-up, order and settings.
- The compose.yaml file — Describing an application and its database instead of long commands.
- Order and readiness — Why “started” does not mean “ready” and how to fix it.
- Variables and secrets — How to pass settings without putting a password into the image.
A production image
Multi-stage builds, security and keeping the disk tidy.
- Multi-stage builds — Build in one image, run in another.
- A secure image — A non-root user, a fresh base and nothing extra.
- Size and clean-up — Finding where image weight comes from and cleaning the disk without losses.