chaidocs
docker-k8s-fundamentals

Docker

Akash Kadlag 14 pages 7 min read Updated Nov 18, 2026
On this page
  1. **Docker** for Dummies
  2. One standard box for software
  3. VMs vs Containers
  4. Dockerfile → Image → Container
  5. Play with Docker
  6. We never installed specific Node version on our machine for this app. The image **brought** it.
  7. Volumes and networks
  8. Real apps need many containers
  9. Docker Compose
  10. The problems revisited
  11. The new challenge: too many containers
  12. Who looks after them?
  13. Container **Orchestration**
Docker for Dummies
chaicode.com
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.

One standard box for software

Your app plus everything it needs like runtime, libraries, config packed into one image that runs the same everywhere.

chaicode.com
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.

VMs vs Containers

Virtual machineContainer
Contains a full guest OS + appJust the app + its libraries
Size: GBsSize: MBs
Starts in minutesStarts in seconds
Strong isolation (separate kernel)Process-level (shared kernel)
Tens per serverHundreds per server

A VM is a whole house. A container is a flat in a building: your own space, shared foundation.

In plain words

Hypervisor Software that runs several complete guest operating systems on one machine

Kernel The core of the operating system; containers share the host's, VMs each bring their own

chaicode.com
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.

Dockerfile → Image → Container

Dockerfilethe recipeImagepackaged snapshotContainerrunning instanceRegistryDocker Hub · GHCR · ECR1docker build2docker run3push / pull
  1. 1docker build turns the Dockerfile recipe into an image
  2. 2docker run starts a container — a running instance of that image
  3. 3docker push / pull shares the image through a registry
In plain words

Image A read-only packaged snapshot of the app and its dependencies

Registry A store for images, like Docker Hub, GHCR or ECR

chaicode.com
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.

Dockerfile

FROM node:24-alpine          # base image to start from
WORKDIR /app                 # working folder inside the container
COPY package*.json ./        # copy files from your machine into the image
RUN npm ci --omit=dev        # runs a command at build time
COPY . .                     # now the rest of the code
EXPOSE 3000                  # documents the port (doesn't publish it; -p does)
CMD ["node", "server.js"]    # command that runs when the container starts
chaicode.com
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.

Play with Docker

Run commands one by one

terminal

docker build -t my-app:1.0 .                      # recipe → image
docker images                                     # there it is, with its size
docker run -d -p 3000:3000 --name web my-app:1.0  # -p host:container
docker ps                                         # it's running
# open localhost:3000
docker logs -f web                                # Ctrl+C to leave   (skip if late)
docker exec -it web sh                            # look inside, exit (skip if late)
docker stop web && docker rm web                  # disposable
chaicode.com
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).
We never installed specific Node version on our machine for this app. The image brought it.
chaicode.com
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.

Volumes and networks

  1. 01VolumesA container's files vanish when it's removed. Volumes keep data outside: docker run -v mydata:/data my-app
  2. 02NetworksContainers on the same network reach each other by name: docker network create appnet
In plain words

Volume Storage managed by Docker that outlives the container it's attached to

chaicode.com
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).

Real apps need many containers

chaicode.com
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.

Docker Compose

Onboarding becomes: clone, docker compose up, start coding.

compose.yaml

services:
  web:
    build: .
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://app:secret@db:5432/app   # 'db' is the hostname
    depends_on:
      - db
  db:
    image: postgres:17
    environment:
      POSTGRES_USER: app
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: app
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data:

terminal

docker compose up -d     # start everything
docker compose down      # stop everything
In plain words

Service One named container definition in compose; its name becomes its hostname on the network

chaicode.com
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.

The problems revisited

Old problemWith Docker
1. Environment driftThe same image runs in dev, CI and production
2. Dependency conflictsEach app carries its own runtime, side by side
3. Slow onboardingClone, docker compose up, start coding
4. Snowflake serversA server only needs Docker; everything else lives in the image
5. Painful rollbacksRun the previous image tag
6. Manual scalingStill manual
chaicode.com
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.

The new challenge: too many containers

Apps grew from one monolith into many microservices: Users, Orders, Payments, Search, Notifications.

10services
×
3copies each
=
30containers across 10 servers
chaicode.com
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.

Who looks after them?

  • Which server has room for this container?
  • A container crashed at 3 AM. Who restarts it?
  • Traffic doubled. Who starts more copies?
  • New version: how do we update with zero downtime?
  • Containers keep moving. How do services find each other?
chaicode.com
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.
Container Orchestration
chaicode.com
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.