LESSON · 1 OF 6

Container states

Container states

A container is not simply on or off. It moves through a small set of states over its life, and knowing which state a container is in tells you what you can do with it.

The main states

  • created - the container exists but has never started. You get this from docker create (a rarely used cousin of run), or briefly before a container starts.
  • running - the main process is alive. This is what docker ps shows.
  • exited - the main process finished, cleanly or not. The container is stopped but still exists, with its writable layer, until removed.
  • paused - the container's processes are frozen in place with docker pause and can be resumed with docker unpause. Used rarely.

The normal path

Most containers walk a simple line: created, then running, then exited. A one-shot command like docker run alpine echo hi blinks through running and lands in exited almost instantly. A service like nginx sits in running until you stop it, then moves to exited.

Status in docker ps

The STATUS column in docker ps -a spells the state out with detail:

text
Up 3 minutes
Exited (0) 10 seconds ago
Exited (137) 2 minutes ago

"Up" means running. "Exited (0)" means it stopped and the process returned exit code 0, a clean finish. "Exited (137)" means it stopped with a non-zero code, which usually signals a problem - the next node is about exactly that.

Commands this node introduces

  • docker pause CONTAINER / docker unpause CONTAINER - freeze and resume a container
Spin up a fresh environment and practice live.
docker · fresh machine · ready in under a minute