Docker

“Works on my machine” — now guaranteed, everywhere.

▶ the lesson · narrated sketch video · tap for sound

the intro

Docker packages your application together with everything it needs — runtime, dependencies, config — into a container. The same container runs identically on your laptop, your teammate’s machine, and production. No more it-works-on-my-machine excuses.

the sample

the whole recipe, 4 lines

FROM node:20
COPY . .
RUN npm ci
CMD ["npm", "start"]

fun fact ✦

Containers share your OS kernel, so they are way lighter than full virtual machines.

the docs

the deep dive

the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid

Every app is a needle in an environment-shaped haystack: the right Node version, the right libraries, the right OS quirks. Containers let you stop describing the haystack and just ship it, sealed, with the needle inside. And because containers share the host kernel instead of virtualizing hardware, they cost seconds and megabytes, not minutes and gigabytes.

ship the environment, not just the code

Dockerfileimagecontainer
the recipe is built once into an image; the image runs as many identical containers

key terms

image

A read-only template: your app plus its runtime, frozen at build time.

node:20-alpine, myapp:1.4

container

A running instance of an image with a thin writable layer on top. Delete it and that layer is gone.

docker run -p 3000:3000 myapp

layer

Each Dockerfile instruction becomes a cached layer. Change code and only the layers after the change rebuild.

the npm ci layer stays cached

volume

A folder Docker manages outside the container, so data outlives the container.

-v pgdata:/var/lib/postgresql

how it works

  1. 1
    Write the Dockerfile

    A dozen lines describing the world: base image, copy code, install, start command. This is the recipe.

  2. 2
    Build the image

    docker build -t myapp . bakes the recipe into cached layers. Change code and only the changed layers rebuild.

  3. 3
    Run a container

    docker run -p 3000:3000 myapp turns the image into a live process. Run it twice and you have two identical copies.

  4. 4
    Ship it anywhere

    docker push puts the exact bytes in a registry. Any machine with Docker pulls and runs the identical thing.

the code, explained

the recipe that becomes the image

1FROM node:20-alpine
2WORKDIR /app
3COPY package*.json ./
4RUN npm ci
build time: dependencies get baked into the image
5COPY . .
6CMD ["node", "server.js"]
run time: starts when a container boots, not when it builds

side by side

container

  • shares the host kernel
  • starts in milliseconds
  • images measured in MB
  • isolation via namespaces
  • cheap: no guest OS to run
VS

virtual machine

  • ships an entire guest OS
  • boots in tens of seconds
  • images measured in GB
  • strongest isolation boundary
  • heavier on RAM and disk
🪤 gotcha

Run docker rm on a container and everything the app wrote inside it vanishes with it. Databases, uploads, sessions — anything you would cry about — belongs in a volume. The container itself should stay disposable.

quick answers

Is Docker a virtual machine?

No. A VM virtualizes hardware and boots a whole operating system; a container is just ordinary processes isolated by namespaces on the shared kernel. That is why they start instantly.

Why did my container's data disappear?

The writable layer dies with the container. Anything that must survive lives in a volume, which down and rm cannot touch.

Alpine or a full base image?

Alpine images run around 130MB where fat ones exceed a gigabyte. One catch: Alpine uses musl libc, so native modules can behave differently — test before you commit.

quick hits about Docker

short answers · interviews, tips, trivia & hidden gems

🎤 interview

Image vs container?watch ↗

🎤 interview

Why do containers isolate?watch ↗

📚 tutorial

Dockerfile lines decodedwatch ↗

📚 tutorial

Build, tag, push, pullwatch ↗

🔧 useful

The five run flags you use dailywatch ↗

💎 deep

Code changes without rebuilds?watch ↗

💎 deep

1GB images → 80MBwatch ↗

💎 deep

Copy files in and out of containerswatch ↗

🔧 useful

Ten times faster buildswatch ↗