Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Infrastructure

How does Docker work? (A container is not a tiny computer)

A container is not a tiny VM. It is a normal process with limited sight (namespaces) and limited resources (cgroups), started from read-only layers.

Derpx062 Nov · 5 min read
Contents
Why do we even need containers?Is a container a tiny VM?What is the blindfold? (namespaces)What is the leash? (cgroups)What is an image, and why layers?How do I make an image?What happens when I type docker run?What should I learn next?Sources
0% read · 5 min leftBack to top ↑
On this page0%
Contents
Why do we even need containers?Is a container a tiny VM?What is the blindfold? (namespaces)What is the leash? (cgroups)What is an image, and why layers?How do I make an image?What happens when I type docker run?What should I learn next?Sources

Run docker run alpine and a whole "Linux" appears in a blink, with no install. So it must be a tiny computer inside your computer, right?

No. A container is just a normal process on your laptop, with a blindfold and a leash. The blindfold is called namespaces, the leash is called cgroups. Let's look at both, and then run one.

Think of it like this

A VM is renting a whole separate house. A container is a room with a closed door in a shared house: same building, same plumbing, but you only see your own room.

Why do we even need containers?

Your project runs on your laptop. Someone else installs it and gets errors, because their Python, libraries or settings are slightly different. Docker's fix: pack the app and everything it needs into one box, so it runs the same everywhere.

The docs describe a container as an ordinary process that runs in isolation, with its own filesystem, its own view of processes, network and hostname, and optional limits on memory and CPU.

Why this matters: one box, same result on every machine. But how is a box different from a virtual machine?

Is a container a tiny VM?

A virtual machine (VM) pretends to be a whole computer, with its own operating system and kernel. The kernel is the core part of the OS that talks to your hardware. A container skips all that.

VMBoots its own OS and kernel. Strong isolation, heavier.
→
ContainerJust a process. Shares the host's kernel. No OS to boot.
The Docker docs say a VM's isolation is stronger. That's the trade-off.

No OS to boot means a container starts much faster than a VM. (The exact time depends on the machine.) The price is that every container on a machine shares one kernel.

Container A
Container B
Docker (the daemon)
One shared Linux kernel
Your hardware
Containers are stacked on the same kernel, not on separate ones.

So a container is a process. But then what makes it feel like its own little world?

What is the blindfold? (namespaces)

The Linux man page explains that a namespace wraps a shared resource so the processes inside see their own private copy of it. The process is not in a different world. It just cannot see the rest of this one.

NamespaceWhat it hides or gives you
PIDIts own process IDs
NetworkIts own network devices, ports and so on
MountIts own mount points (the filesystem view)
UTSIts own hostname
IPCIts own message queues between processes
UserIts own user and group IDs

Inside a container your app can be "process number 1" and see no other processes. On the real machine it is one process among hundreds.

Why this matters: namespaces limit what a process can see. But a process can still eat all your RAM. What stops that?

What is the leash? (cgroups)

Control groups, cgroups, control what a process can use. The man page explains that they organise processes into groups so their resource use can be limited and monitored.

There are controllers for different resources. memory limits memory, cpu can cap CPU time, and pids limits how many processes the group can create.

Container

A normal Linux process, put in its own namespaces and a cgroup, running from an image.

That "from an image" part is next.

What is an image, and why layers?

An image is the package a container starts from: the OS files, runtime, libraries, your code and the default command. Images are immutable, so once built they never change. To change one, you build a new one.

An image is a stack of layers. Each layer is a set of file changes on top of the one below, and all of them are read-only.

Your code
npm install result
package.json
Node.js
Debian base
Layers, top to bottom. Each one only records what changed.

When a container starts, Docker adds one thin writable layer on top. Everything the app writes goes there, and deleting the container deletes it. The image underneath stays untouched.

Layers get shared too. Two containers from the same image share all the read-only data, and shared layers are stored once. For example, if 10 people download the same file, the server can keep just one copy.

How do I make an image?

Three terms, one pipeline. A Dockerfile is a text file with the steps to build an image. You run the image to get a container.

1Dockerfile (instructions)
2Image (read-only layers)
3Container (running process)
Same image, as many containers as you want.

Here's a tiny Dockerfile:

Dockerfile
FROM node:24-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
CMD ["node", "src/index.js"]

FROM picks the base image. RUN runs a command and makes a new layer. CMD is what runs when the container starts. Layers are cached, so if you copy package.json first and your code later, editing your code won't redo npm ci. That order trick is straight from Docker's docs on layers.

Now let's see the whole thing happen.

What happens when I type docker run?

Run this (you need Docker installed):

Bash
docker run --rm -it --memory 256m alpine sh

Click Next and follow the request from your terminal down to the running process.

docker client
dockerd (daemon)
alpine image
Container process

The docker client sends your request to dockerd over a local socket

Step 1 of 4
The daemon is the persistent process that manages containers. --rm deletes the container when you exit.

The daemon does the real work, and the client only sends requests. Now try it: inside the shell, type hostname. It is not your laptop's name, because the container has its own hostname (that's the UTS namespace).

Type exit and it's gone. Run docker pull node:24-slim next and watch the output. Layers you already have say Already exists, which is the sharing in action.

What should I learn next?

  • Volumes, so data survives when the container is deleted.
  • Docker Compose, for running an app plus its database together.
  • Networking: how containers talk to each other and to you.
  • The docker run flags --pid, --userns and similar ones, which let you choose which namespaces a container uses.
Key takeaways
  • A container is a normal process, not a tiny VM. It shares the host's kernel.
  • Namespaces limit what it can see, and cgroups limit what it can use.
  • An image is a stack of read-only layers. A running container only adds one thin writable layer on top.
  • Dockerfile builds the image, and the image runs as a container.

Sources

  • Docker docs: What is a container?
  • Docker docs: What is an image?
  • Docker docs: Understanding image layers
  • Docker docs: Storage drivers
  • Docker docs: Dockerfile reference
  • Docker docs: dockerd and docker container run
  • Linux man pages: namespaces(7) and cgroups(7)
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Infrastructure · 4 minHow does Kubernetes work?Foundations · 3 minWhy is 0.1 + 0.2 not 0.3 in code?Foundations · 4 minHow does Git work inside? (Snapshots, not changes)
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)