Reviewing Docker Container Exit Codes
Explore how to analyze Docker container exit codes and signals to identify why containers stop or fail. Learn to interpret common exit codes like 0, 1, 127, and 137, and apply troubleshooting steps to fix build and runtime errors. This lesson helps you manage container lifecycle events effectively to optimize Docker container usage and handle issues promptly.
Docker container exit codes are
When a Docker container exits, it means that the container won’t be found among running containers in the environment. It’ll only be found under exited containers with the docker ps -a command.
Reviewing Docker container exit codes
We’ll be reviewing Docker container exit codes, but before going into that we’ll need to understand some signs that are shown on the environment when a container exits.
Understanding signals
In the UNIX operating system, signals are used for communication between objects in the environment. The same scenario is also applicable in the Docker container environment to manage the container life cycle. Here are some of the common signals used in Docker:
The
SIGINT (2)signal: This signal is sent when the user uses the “Ctrl+C” keys from their keyboard. Sending this will cause the container to stop and exit.The
SIGTERM (15)signal: This signal is used to process termination on the Docker environment. Sending this signal will shut down the container.The
SIGKILL (9)signal: This signal is used for the forceful termination of containers in Docker. It makes Docker perform termination without a chance to clean up any resource within.The
SIGHUP (1)signal: This signal is sent to start up or close a session. In Docker’s scenario, it’ll restart the container.The
SIGUSR1 (10)andSIGUSR2 (12)signals: ...