In this lesson, you will learn how to verify exactly what your container is doing and which lifecycle phase it currently occupies using standard inspection tools.
The Lifecycle of a Container
When you start a container, it doesn't just "exist"—it undergoes a series of transitions. It moves from being created (defined but not running) to running (executing its entrypoint process), and eventually to exited (stopped) or dead. To effectively manage containers, you must be able to peer into the container runtime to confirm its current operational status.
Using docker inspect
The primary way to verify the runtime state is by utilizing the docker inspect command. This tool queries the Docker daemon, which communicates with the runtime (like runc) to retrieve the raw state data of your container.
When you run a command like:
docker inspect <container_id>
You will receive a massive block of JSON metadata. Within that output, look specifically for the State object. It looks something like this:
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1234,
"ExitCode": 0,
"StartedAt": "2023-10-27T10:00:00Z"
}
Interpreting the Output
- Status: This tells you the broad lifecycle phase (e.g.,
running,exited). - Running: A simple boolean that confirms if the primary process is currently active.
- Pid: This reveals the Process ID assigned by the host operating system, proving that the runtime has successfully handed off the process to the kernel.
- ExitCode: If the status is
exited, this field will tell you why it stopped. AnExitCodeof0typically indicates a clean finish, while anything else suggests a crash or error.
By inspecting these fields, you move beyond guessing what your container is doing and start making evidence-based decisions about its health. Whether you are debugging a container that won't start or verifying one that finished a job, these runtime states provide the ground truth for your environment.
Key Takeaway: Use docker inspect to examine the State object, which acts as the definitive source of truth for your container's current lifecycle phase and process status.