Repaso
Español
Cloud & DevOpsIntermediateOPS-06

A container starts and exits immediately with code 0. Most likely cause?

Options

  1. The container ran out of memory and was stopped by the system
  2. Its main process (PID 1) finished, like a script that simply ended (Correct option)
  3. The image is corrupt, so the container cannot keep running
  4. The Docker daemon crashed and stopped every running container

Answer

Its main process (PID 1) finished, e.g. the command ran a script and returned

Why

A container lives exactly as long as its main process. Exit code 0 means that process ended successfully: there was simply nothing left to do.

Common causes: the command runs a short script, or starts a server in the background (daemon mode) and then returns.

Run the server in the foreground as the main process.

Remember

Main process ends → container stops.

Key terms

Practice this question in Repaso