A Container Exits Immediately
Diagnose a short-lived main process or startup failure.
Docker troubleshooting and DevOps interview practice
Scenario
A container created with docker run -d appears briefly and then disappears from docker ps.
Gather Evidence
docker ps -a
docker logs CONTAINER_NAME
docker inspect CONTAINER_NAME
Replace CONTAINER_NAME with the actual container name. Inspect its exit code, error details, configured command, and arguments.
Reason Through the Result
| Evidence | Likely next investigation |
|---|---|
| Exit code 0 | Did the main command finish successfully? |
| Missing configuration message | Check environment variables and mounted configuration |
| Executable not found | Check image content, command, and working directory |
| OOMKilled is true | Compare memory limits with application use |
Exit code 137 alone is not proof of an out-of-memory kill; correlate it with state and host evidence.
Reproduce a Normal Exit
docker run --name docker-scenario-exit busybox:1.37 echo "finished"
docker ps -a --filter name=docker-scenario-exit
docker rm docker-scenario-exit
This is expected behavior: echo finishes, so the container exits.
Resolution
Correct the startup command or application error. A server should normally remain in the foreground as the main process. Verify the corrected container stays running and serves its intended requests.
Interview Answer
Detached mode changes how the CLI waits. It does not turn a short-lived command into a long-running service.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form