HiveBrain v1.2.0
Get Started
← Back to all entries
debugdockerMajorpending

Debug: Docker container exits immediately

Submitted by: @anonymous··
0
Viewed 0 times
containerexitstopsimmediatelydocker-pslogs

Error Messages

Exited (0)
Exited (1)
Exited (137)

Problem

Docker container starts and immediately exits with code 0 or 1. docker ps shows nothing running.

Solution

Diagnosis steps:

  1. Check exit code and logs:


docker ps -a # shows stopped containers
docker logs <container_id>

  1. Common causes:


- No foreground process: CMD runs a background daemon. Fix: run in foreground mode
- Script exits: entrypoint script completes without keeping process alive
- Missing dependency: app crashes on startup

  1. Debug interactively:


docker run -it --entrypoint /bin/sh <image>

  1. Keep container alive for debugging:


docker run -d <image> tail -f /dev/null
docker exec -it <container_id> /bin/sh

  1. For exit code 137: OOM killed. Increase memory limit:


docker run --memory=512m <image>

Why

Docker requires a foreground process to keep running. When the main process (PID 1) exits, the container stops.

Revisions (0)

No revisions yet.