Journeys · Docker · L0
From docker run to a running container
One command. Four programs. One of them is gone before you see the ID.
✓ Validated on Docker Engine 29.9.3 · Run 1 · 2026-11-20Preview
The 30-second answer
The docker CLI sends your command to dockerd as HTTP requests: create, then start. dockerd hands the container to containerd. containerd starts a shim for it. runc reads a file called config.json, sets up the namespaces it lists, starts redis-server and exits. The shim stays behind as the parent of your container's first process.
Mental model
A restaurant. You give your order at the desk (dockerd). The kitchen manager (containerd) books it. A waiter (the shim) is assigned to your table. A cook (runc) follows the recipe card (config.json), puts the dish on your table and goes back to the kitchen.
Where the analogy breaks
The dish is not food that sits there. It is a process that keeps running inside its own walls: its own view of mounts, network, process IDs and hostname. And the cook does not wait around: runc exits as soon as the process is started. Only the shim stays.
Press play and watch the story unfold.
Event stream
Click a row to inspect it| # | Time | From → To | Kind | What |
|---|---|---|---|---|
| Press play. Each hand-off appears here, like a packet capture. | ||||
Predict, then check
Which program is the parent of redis-server: dockerd, containerd or the shim?
The shim. pstree shows containerd-shim, PID 4813, with redis-server as its child, and ps shows the shim's own parent is PID 1.
Inside the container you run ps. Which PID does redis-server have, and why not 4839?
PID 1. config.json asked for a new pid namespace, so the container numbers its processes from 1. The host numbers the same process 4839.
Transcript
The whole journey as text, for reading, searching and screen readers.
The CLI calls dockerd
The docker CLI does not run containers. It is a client of the Engine API, an HTTP API that dockerd serves on a Unix socket. To record what it sends, the capture pointed the CLI at a relay with DOCKER_HOST. The relay logs every request line and passes every byte on unchanged. The first thing the CLI sends is a ping.
Insight: Every docker command is HTTP underneath. You can send the same requests with curl, and the API version is part of each path.
docker CLI→dockerd: HEAD /_ping → 200 OK
Create, with every setting written out
Next the CLI sends POST /v1.56/containers/create?name=redis. The body is JSON: the image, the network and every setting you did not type, filled with empty or zero values. dockerd answers 201 Created. The start comes later, in a separate request.
Insight: Create and start are two steps. That is why docker create exists as its own command.
docker CLI→dockerd: POST /v1.56/containers/create?name=redis → 201 Created
Wait, then start
On the first connection the CLI asks to wait for the container's next exit. The Engine API reference says this call blocks until a container stops, then returns the exit code. Then the CLI opens a second connection and sends start. dockerd answers 204 No Content, and the CLI prints the container's ID.
Insight: The ID the CLI prints is the one in the start request's path. Its first 12 characters become the container's hostname.
docker CLI→dockerd: POST …/wait?condition=next-exit → 200 OKdocker CLI→dockerd: POST …/start → 204 No Content
dockerd hands over to containerd
dockerd does not start processes itself. It is a client of containerd, a daemon that manages containers through a gRPC API. ctr, containerd's debugging tool, shows the result. Docker's containers live in a containerd namespace called moby. The container has the same ID and the runtime io.containerd.runc.v2. Its running part, which ctr calls a task, has PID 4839.
Insight: containerd namespaces keep clients apart on one daemon. Docker's containers are in moby, so a plain ctr containers ls without -n moby does not list them.
dockerd→containerd: create and start container c6e0b658080c… (namespace moby)containerd→containerd: task c6e0b658080c… RUNNING, PID 4839
A shim for this container
containerd starts /usr/bin/containerd-shim-runc-v2 with the container's ID, the namespace moby and containerd's own address. The process tree shows the shim, PID 4813, with redis-server as its only child. ps shows the shim's own parent is PID 1, not containerd.
Insight: The container's first process is a child of the shim, not of dockerd or containerd. The shim is what watches it.
containerd→containerd-shim: start containerd-shim-runc-v2 -id c6e0b658080c…containerd-shim→containerd-shim: parent of the shim: PID 1
runc does the work, then leaves
runc is the program that creates containers from an OCI bundle: a folder with a root filesystem and a config.json. The shim's options name the binary runc and a state folder. runc reads the bundle, sets the container up and starts its first process. Then it exits. pgrep finds no runc process, yet runc list still knows the container from the state it left.
Insight: runc is not a daemon. While the container runs, no runc process does.
containerd-shim→runc: run runc with the bundlerunc→runc: runc state: running, bundle …/moby/c6e0b658080c…runc→runc: runc processes now running: 0
The recipe card: config.json
config.json follows the OCI runtime specification. It was written for this one container: its hostname and cgroup path carry the container's ID. It names the program to start, docker-entrypoint.sh redis-server, as uid 0 in /data. It lists six namespaces for runc to create: mount, network, time, uts, pid and ipc. It names a cgroup path, /docker/ followed by the container ID.
Insight: There is no cgroup or user entry in the namespaces list, so the container shares those two with the host. cgroup v1 has one tree per controller; cgroup v2 has a single tree. So the files at that path differ, and journey 5 reads them on Docker Desktop.
runc→Linux kernel: create namespaces, place the process in cgroup /docker/c6e0b658080c…
New walls, checked from the host
Every process has links in /proc/<pid>/ns, one per namespace. Two processes in the same namespace show the same number. Compare redis-server, PID 4839, with a process on the host. mnt, net, pid, ipc, uts and time differ: the six from config.json. cgroup and user are the same as the host's.
Insight: On this cgroup v1 host the container shares the host's cgroup namespace. docker run's --cgroupns flag defaults to the daemon's setting. Version note: on Docker Desktop (validation Run 2, cgroup v2) docker inspect showed CgroupnsMode private, /proc/1/cgroup in the container read 0::/, and /sys/fs/cgroup held one tree with memory.max and the other v2 files.
Linux kernel→redis: redis-server runs inside new mnt, net, pid, ipc, uts, time namespacesLinux kernel→Linux kernel: for comparison: a process in the host's namespaces
PID 1 inside, PID 4839 outside
The entrypoint script ends in exec: it switches to the user redis with setpriv and replaces itself with redis-server. Inside the container, ps shows redis-server as PID 1, user redis. On the host, docker top shows the same process as PID 4839, child of the shim, PID 4813. The container's hostname is the first 12 characters of its ID.
Insight: A container is a process with its own namespaces. If PID 1 exits, the container stops.
redis→redis: inside: redis-server is PID 1redis→redis: the entrypoint hands over with execredis→Linux kernel: outside: the same process is PID 4839docker CLI→redis: the container's hostname: c6e0b658080c
Go deeper
- Docker Engine API
- Docker Engine API: Wait for a container
- docker container run (reference): --cgroupns, --network
- containerd: Getting started (namespaces, the gRPC client)
- containerd README
- containerd runtime v2 (shims)
- runc README (OCI bundles, config.json, --root)
- namespaces(7), Linux manual page
- Control Group v2 (Linux kernel documentation)