docker-k8s-fundamentals
Docker
On this page
- **Docker** for Dummies
- One standard box for software
- VMs vs Containers
- Dockerfile → Image → Container
- Play with Docker
- We never installed specific Node version on our machine for this app. The image **brought** it.
- Volumes and networks
- Real apps need many containers
- Docker Compose
- The problems revisited
- The new challenge: too many containers
- Who looks after them?
- Container **Orchestration**
Notes
This chapter is about Docker: a way to package an application together with its dependencies into a container.
The core idea: build the container once, run it unchanged on a laptop, a test machine or in production.
We will look at why this matters and how containers are built and run.
Notes
Docker packages your app plus everything it needs — the runtime, the libraries, the config — into one unit called a container image.
That image runs the same way on your laptop, in CI and in the cloud.
Before standard shipping containers, cargo came in every shape and was loaded by hand at every port. After, one standard box could go on any ship, crane or truck.
Docker is that standard box for software.
Notes
A VM contains a full guest operating system plus the app; a container is just the app and its libraries, sharing the host's kernel through the Docker Engine.
That's why VMs are gigabytes and start in minutes, while containers are megabytes and start in seconds — tens per server versus hundreds.
Common question: on Mac and Windows, Docker Desktop runs a small Linux VM behind the scenes, because containers need a Linux kernel.
Containers didn't replace VMs. In the cloud, containers usually run on VMs.
Notes
The Dockerfile is the recipe. docker build turns it into an image, a packaged snapshot. docker run turns the image into a container, a running instance.
Image to container is like class to object: one image can run as many containers as you like.
Images are shared through a registry — Docker Hub, GitHub Container Registry, Amazon ECR — with docker push and docker pull.
For students: a recipe, then a packed meal kit, then a meal being cooked.
Notes
FROM picks the base image. WORKDIR sets the folder inside the container. COPY brings files in from your machine. RUN executes a command at build time.
EXPOSE only documents the app's port — it does not publish it; the -p flag does that at run time. CMD is what runs when the container starts.
Say: look at what this file really is. It's the 2 AM runbook from earlier, the one people followed by hand, written as code that a machine runs the same way every time.
Pro tip: copy package.json first and the rest of the code later. Docker caches each layer, so if only your code changes, npm ci doesn't re-run.
Notes
Hard limit six minutes. Narrate one sentence per command, then run it. If running late, skip docker logs and docker exec.
Safety: pre-pull node:24-alpine and postgres:17. Have a .dockerignore with node_modules and .git so COPY . . is fast. Build once beforehand so layers are cached and the live build takes seconds.
Increase the terminal font size; clear the terminal before starting.
Keep a screen recording as a backup. If anything fails twice, switch to the recording and keep talking.
Closing line: that was five minutes. Docker done properly, hands-on, needs hours — that's what I'm recording next (channel mention 3).
Notes
This is the one sentence the demo exists for. The runtime came inside the image, not from the machine.
That is the whole promise: the environment travels with the app, so the host only needs Docker.
Notes
Volumes: a container's files vanish when it's removed. Volumes store data outside the container — docker run -v mydata:/data my-app.
Networks: containers on the same network reach each other by name — docker network create appnet.
Key line: inside a container, localhost means the container itself.
If you watched the networking video, this is the same ports and DNS, just inside containers (channel mention 2).
Notes
A typical app is web plus API plus database plus a cache like Redis.
Starting each one with a long docker run command, in the right order, with the right network, is painful.
The pattern again: the fix was one container; the new pain is four containers, started by hand.
Notes
web reaches the database at db:5432, because the service name is the hostname. The old version: "3" line is no longer needed.
If on time, run docker compose up -d and docker compose ps live (30 seconds). If not, just show the file.
The password is in the file because this is local development. In real projects it comes from an .env file or a secret manager.
Likely question: depends_on controls start order only. It doesn't wait for Postgres to be ready; a healthcheck does that.
Notes
Environment drift: the same image runs in dev, CI and production. Dependency conflicts: each app carries its own runtime, side by side.
Slow onboarding becomes clone, docker compose up, start coding. Snowflake servers: a server only needs Docker; everything else lives in the image. Rollbacks: run the previous image tag.
Say: this is why Docker won. Not because it was new, but because it closed five of the six problems on our list in one move.
And look at number six. It's still standing. That one problem is the whole reason the next tool exists.
Notes
Apps grew from one monolith into many microservices — Users, Orders, Payments, Search, Notifications.
Ten services times three copies each is thirty containers, spread across ten servers.
Docker made containers so easy that we created too many of them.
Notes
Which server has room? Who restarts a crashed container at 3 AM? Who starts more copies when traffic doubles?
How do we roll out a new version with zero downtime? When containers keep moving, how do services find each other?
Compose runs many containers on one machine. None of these questions are answered on a single machine.
Notes
Docker made containers so easy that we created too many of them.
Compose runs many containers on one machine. We need something to manage them across many machines.
That's Kubernetes — the subject of the next chapter.