In this lesson, you will learn how to interpret the numeric exit codes your containers provide to diagnose whether they stopped successfully or crashed due to an error.
When a container stops, it doesn’t just "disappear." It leaves behind an exit code—a status number that acts as a shorthand report for the runtime environment (like Docker or Kubernetes) to understand why the process ended.
Reading the Status Code
You can see this code by running docker inspect <container_id>. Look for the "State": { "ExitCode": ... } field. These numbers follow standard Linux conventions:
- Exit Code 0: This is the "Gold Standard." It means the process completed exactly what it was instructed to do and exited gracefully. In CI/CD pipelines, a
0tells your automation server that the task succeeded. - Exit Code 1: This is the most common "Catch-all" error. It usually indicates that the application encountered a general error, such as a missing configuration file, a syntax error in your script, or an unhandled exception.
- Exit Code 127: This code is specific; it means "Command Not Found." If you see this, your container likely tried to execute a binary or script that doesn't exist inside the image path.
- Exit Code 137: This is a vital signal in production environments. It indicates that the process was killed by a
SIGKILLsignal, typically because the container ran out of memory (OOM) and the host kernel stepped in to terminate it to save the system.
Why This Matters for Automation
If you are managing containers in a CI/CD pipeline, your tools use these codes to decide whether to continue the deployment or halt everything. If a test container exits with a 1, your pipeline will automatically recognize the failure and block the code from moving to production. By checking these codes manually, you move from "guessing why it crashed" to knowing exactly which stage of your logic failed.
Key Takeaway: An exit code of 0 confirms a clean execution, while non-zero codes act as specific diagnostic signals that tell you exactly why your container process terminated.