
How to Check Docker Container Exit Codes
To view the exit code of a stopped container:docker inspect <container_name_or_id> --format='{{.State.ExitCode}}'
Common Docker Exit Codes
Exit Code 0: Success- Meaning: The container completed its process successfully.
- Example: If a simple container runs a script that prints “Hello, World!” and finishes without errors, it will exit with code 0.
docker run hello-worldExit Code 1: Generic Error
- Meaning: A generic catch-all error code, typically related to application logic.
- Example: A Python container runs a script with a syntax error, and it throws an exception, leading to exit code 1.
docker run python:3.8 python -c 'print(Hello World)'This will cause a syntax error because the string
Hello World lacks quotes.
Exit Code 137: Out of Memory (OOM) or Killed
- Meaning: The container was terminated by the system, usually because it ran out of memory or was manually killed with the
kill -9signal. - Example: A Java application using excessive memory causes the system to terminate it due to memory constraints.
docker run --memory="50m" openjdk java -Xmx512m MyAppExit Code 139: Segmentation Fault
- Meaning: A segmentation fault occurred, often due to a low-level issue with memory access.
- Example: A C program attempts to access memory incorrectly, causing the container to crash.
docker run gcc /bin/bash -c "echo 'int main(){int *p = 0; *p = 1;}' > segfault.c && gcc segfault.c -o segfault && ./segfault"
Exit Code 143: Gracefully Stopped by SIGTERM
- Meaning: The container received the SIGTERM signal and stopped gracefully.
- Example: A container running a web server is stopped using docker stop, which sends a SIGTERM signal.
docker stop <container_name_or_id>Exit Code 127: Command Not Found
- Meaning: The command inside the container could not be found or executed.
- Example: Running a container that tries to execute a non-existent command.
docker run ubuntu sh -c 'non_existing_command'Exit Code 126: Command Cannot Be Invoked
- Meaning: The command exists but cannot be executed, usually due to permission issues or an invalid executable.
- Example: Running a script inside a container without execution permissions
docker run ubuntu bash -c 'chmod -x /bin/ls && /bin/ls'Exit Code 255: Unknown Error
- Meaning: An unknown or application-specific error occurred.
- Example: An application returns an exit code that isn’t one of the standard codes, often for app-specific reasons.
- Meaning: This error occurs when there’s improper use of shell commands or a syntax error in the script.
- Example: A bash script with invalid syntax or misuse of a shell built-in command can cause this error.
docker run ubuntu bash -c 'exit 3'Exit Code 125: Docker Command Itself Failed
- Meaning: Docker failed to run the container due to an issue with the Docker command itself. This could be caused by incorrect options or an issue with Docker’s internals.
- Example: Trying to run a container with a bad option:
docker run --wrong-option ubuntuExit Code 130: Script Terminated by Control+C (SIGINT)
- Meaning: The container was terminated by the user pressing
Ctrl+C, sending aSIGINT(interrupt signal). - Example: If a user manually stops a running container by interrupting the process:
docker run ubuntu sleep 100 # Press Ctrl+C to stop the containerExit Code 137: Forced Kill (SIGKILL)
- Meaning: Similar to Exit Code 137, but this specific signal (SIGKILL) happens when the container is forcefully killed, often using the
docker killcommand. - Example: Killing a running container forcibly:
docker run ubuntu sleep 100 docker kill <container_name_or_id>
- Exit Code 143: Graceful Shutdown by SIGTERM
- Meaning: As mentioned, this occurs when the container receives the
SIGTERMsignal and shuts down gracefully, often due todocker stop. - Exit Code 255: Custom or Application-Specific Code
- Meaning: Some applications might use exit code 255 for their own specific errors. This isn’t a standard code but is often used to indicate an unknown or custom application-level failure.
- Example: Running a custom app that returns a 255 exit code:
docker run my_custom_app --exit 255Exit Code 129: Hangup (SIGHUP)
- Meaning: This indicates that the container received a hangup signal (SIGHUP), often from the terminal or session being closed.
- Example: If a session gets disconnected or a process is terminated remotely:
docker run ubuntu bash -c 'kill -1 $'Exit Code 137: Out of Memory (OOM)
- Meaning: Although already mentioned, this exit code can also be caused specifically by an out-of-memory (OOM) event, where the container is killed by the system due to excessive memory consumption.
- Example: Running a memory-intensive Java application:
docker run --memory="100m" openjdk java -Xmx512m -jar myapp.jarExit Code 141: Write to a Pipe with No Reader (SIGPIPE)
- Meaning: The container received a
SIGPIPEsignal, which happens when it attempts to write to a pipe that has no active reader. - Example: A process writes to a closed pipe, leading to exit code 141.
docker run ubuntu bash -c 'echo "data" | false'Exit Code 143: Gracefully Killed (SIGTERM)
- Meaning: The container was terminated using a SIGTERM signal, usually from
docker stop. This allows the process to exit gracefully and clean up resources before shutting down. - Example: If you stop a container gracefully:
docker stop <container_name_or_id>Other Exit Codes
- Exit Code 2: Misuse of shell built-ins, or a command line syntax error.
- Exit Code 126: Permission denied when trying to run a command.
- Exit Code 128: Invalid argument to exit, such as using an invalid signal in the
killcommand.
How to Troubleshoot Docker Issues with Real Examples
Reclaiming Docker Cache Disk Space with Docker Builder Prune
Frequently Asked Questions
What does Docker exit code 125 mean?
Exit code 125 means the docker run command itself failed, not the container’s process, usually because of a bad flag, invalid option, or a Docker daemon issue. Check the exact docker run command you used for a typo or unsupported flag.
What does Docker exit code 255 mean?
Exit code 255 is a catch-all for an unknown or application-specific error. It isn’t one of Docker’s standard signal-based codes, so check your application’s own logs and exit code documentation for what it specifically means in that app.
What does Docker exit code 137 mean?
Exit code 137 means the container was killed, most commonly because it ran out of memory (OOM) or was stopped with docker kill (SIGKILL). Check docker inspect for OOMKilled: true, and consider raising the container’s memory limit.
How do I check a Docker container’s exit code?
Run docker inspect CONTAINER –format='{{.State.ExitCode}}’ to print just the exit code, or docker ps -a to see exit codes for all recently stopped containers in the status column.






Leave a Reply