Scenario Docker Intermediate

A Container Exits Immediately

Diagnose a short-lived main process or startup failure.

1 min read
— Steps
1 Services Used
~30 min Duration
Intermediate Difficulty
The Situation

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

EvidenceLikely next investigation
Exit code 0Did the main command finish successfully?
Missing configuration messageCheck environment variables and mounted configuration
Executable not foundCheck image content, command, and working directory
OOMKilled is trueCompare 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.


Docker Roadmap

Services Used
Docker
Prerequisites
  • Docker fundamentals

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form