fivenines
18/40
Lesson 18 · Runtime

The Container Lifecycle

In one sentence: A container is a state machine — created, running, paused, exited, dead — and every CLI command is just a request for one specific transition.

You already know

  • From Lesson 13: the container store tracks each instance's state.
  • From Lesson 3: the shim outlives everything and reports the process's exit.

States are promises

Each state is a promise about what exists. Created: filesystem mounted, config written, network allocated — but no process; you can inspect it, copy files in, but it consumes no CPU. Running: the process lives. Paused: the process exists but its cgroup is frozen — mid-instruction, consuming memory but zero CPU. Exited: the process is gone but the writable layer and logs remain — debuggable, restartable. Dead: removal failed partway; a tombstone. Removal is only legal from a stopped state — run is not a state but a composite: create + start.

Architecture — the full state machine
stateDiagram-v2
  [*] --> Created: create (fs + config ready, no process)
  Created --> Running: start
  Running --> Paused: pause (cgroup freeze)
  Paused --> Running: unpause
  Running --> Exited: process exits or stop/kill
  Exited --> Running: restart
  Created --> [*]: rm
  Exited --> [*]: rm
  Running --> [*]: rm -f (force)
  Exited --> Dead: rm failed midway
  Dead --> [*]: rm (retry cleanup)
    

Who moves the needle

Transitions have two sources: user commands (start, pause, stop) and reality — the process can exit on its own at any moment, and the state machine must follow the world, not fight it:

Sequence — a crash moves the state, not the user
sequenceDiagram
  participant U as User
  participant E as Engine
  participant CS as Container store
  participant S as Shim
  U->>E: start c-42
  E->>CS: state: Created → Running
  note over S: hours later, the app segfaults
  S->>E: exit event (code 139)
  E->>CS: state: Running → Exited (139)
  U->>E: pause c-42
  E-->>U: error: container not running
    

Anchor these

  • Created ≠ Running: filesystem and config exist before any process does.
  • Exited keeps the writable layer and logs — death is debuggable.
  • The state machine tracks reality; exits arrive as events, not commands.
Next step

See what actually stuck.

Take the practice scenarios now.