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.
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.
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?
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.
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.
So a container is a process. But then what makes it feel like its own little world?
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.
| Namespace | What it hides or gives you |
|---|---|
| PID | Its own process IDs |
| Network | Its own network devices, ports and so on |
| Mount | Its own mount points (the filesystem view) |
| UTS | Its own hostname |
| IPC | Its own message queues between processes |
| User | Its 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?
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.
A normal Linux process, put in its own namespaces and a cgroup, running from an image.
That "from an image" part is next.
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.
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.
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.
Here's a tiny 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.
Run this (you need Docker installed):
docker run --rm -it --memory 256m alpine sh
Click Next and follow the request from your terminal down to the running process.
The docker client sends your request to dockerd over a local socket
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.
docker run flags --pid, --userns and similar ones, which let you choose which namespaces a container uses.