Container lifecycle management encompasses the complete journey of a container from creation through termination, including state transitions, process handling, and cleanup. Understanding lifecycle mechanics is critical for building resilient containerized applications that start correctly, handle signals gracefully, and shut down without data loss or dropped connections. The most common pitfall is the PID 1 problem—when your main process doesn't properly reap zombie children or handle termination signals, leading to resource leaks and unclean shutdowns that orchestrators like Kubernetes misinterpret as application failures.
What This Cheat Sheet Covers
This topic spans 15 focused tables and 120 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Container States
The six official Docker container states form the foundation of lifecycle reasoning; every container is in exactly one of these states at any moment, and transitions between them are triggered by specific commands or conditions.
| State | Example | Description |
|---|---|---|
docker start my-container | • Main process (PID 1) is executing • container is operational and consuming resources. | |
docker create nginx | • Container exists but has not been started • filesystem and config are prepared, no process is running. | |
docker ps -a shows Exited (0) | • Main process terminated with exit code • container stopped but resources not yet cleaned. |