debugdockerMajorpending
Debug: Docker container exits immediately
Viewed 0 times
containerexitstopsimmediatelydocker-pslogs
Error Messages
Problem
Docker container starts and immediately exits with code 0 or 1. docker ps shows nothing running.
Solution
Diagnosis steps:
docker ps -a # shows stopped containers
docker logs <container_id>
- 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
docker run -it --entrypoint /bin/sh <image>
docker run -d <image> tail -f /dev/null
docker exec -it <container_id> /bin/sh
docker run --memory=512m <image>
- Check exit code and logs:
docker ps -a # shows stopped containers
docker logs <container_id>
- 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
- Debug interactively:
docker run -it --entrypoint /bin/sh <image>
- Keep container alive for debugging:
docker run -d <image> tail -f /dev/null
docker exec -it <container_id> /bin/sh
- 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.