June 10, 2026 · 5 min read
Docker container keeps restarting — how to debug
A restart loop usually means the main process exits immediately. Check docker logs, inspect exit code, verify env vars and volumes, and fix the crash—not the restart policy first.
If a Docker container keeps restarting, the process inside is crashing—not “Docker being flaky.” Read logs and exit codes before changing restart policies or rebuilding images.
Debug steps
-
Logs
docker ps -a docker logs CONTAINER_NAME --tail 100 -
Exit code
docker inspect CONTAINER_NAME --format '{{.State.Status}} exit={{.State.ExitCode}} error={{.State.Error}}'Exit
137often means OOM killed.1is generic app failure. -
Run interactively (bypass restart loop)
docker run -it --rm --entrypoint /bin/sh IMAGEOr override command in compose temporarily to
sleep infinityand exec in. -
Check compose / run config
- Missing
DATABASE_URL, wrong volume mount path - Port already in use on host
- Healthcheck too aggressive before app is ready
- Missing
-
Resources
docker stats --no-stream dmesg | tail # OOM killer messages
Common causes
| Clue | Fix |
|---|---|
| ”connection refused” to DB | Start DB first, fix network alias |
| ”permission denied” on volume | UID/GID mismatch, fix ownership |
| Works locally, fails on VPS | Wrong arch image, missing .env on server |
| OOM 137 | Increase memory limit or fix leak |
Production caution
Do not docker system prune -a on a live box to “fix” things. Do not remove volumes without knowing their names.
Get help without YOLO commands
Ohuriya AI is an AI DevOps Copilot—you can paste docker logs output and approve diagnostic commands one at a time. Connect your VPS · disk full fixes
Quick answers
Why does my Docker container keep restarting?
The container entrypoint exits with an error—bad config, missing env var, port conflict, or failed healthcheck. Docker restarts it because of --restart unless-stopped or compose restart policy.
What command shows why a container crashed?
docker logs CONTAINER --tail 100 and docker inspect CONTAINER --format '{{.State.ExitCode}} {{.State.Error}}'. Run docker events in another terminal while reproducing.
Should I change restart policy to fix a loop?
No— that hides the crash. Fix the exit reason first. Temporarily docker update --restart=no only to stop the noise while debugging.