A container starts and exits immediately with code 0. Most likely cause?
Options
- The container ran out of memory and was stopped by the system
- Its main process (PID 1) finished, like a script that simply ended (Correct option)
- The image is corrupt, so the container cannot keep running
- 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.