Primary sources
Decision table: Exit codes, causes, and fixes
| Exit code | Meaning | Typical cause | Fix |
|---|---|---|---|
0 | Normal exit | The container finished its work (intentional exit) | No action needed |
1 | Application error | Application runtime error | Review logs; check env vars and ports (docker logs, docker inspect) |
137 | SIGKILL | OOM Killer or docker kill | Check memory usage and raise the limit (docker stats, docker run -m 512m, docker-compose.yml mem_limit: 512m) |
139 | Segfault | Application memory corruption | Debug the code and improve memory handling |
143 | SIGTERM | Clean shutdown after docker stop | No action needed |
Step 1 — Check status and exit code
# All container statuses (including stopped)
docker ps -a
# Example output
# CONTAINER ID IMAGE STATUS NAMES
# abc123 myapp Restarting (1) 5s ago myapp
# def456 nginx Exited (137) 2 minutes ago nginx
# ↑ exit codeStep 2 — Check container logs
# Last 100 lines of logs
docker logs --tail 100 container-name
# Follow logs in real time (useful while restarts are looping)
docker logs -f container-name
# Include timestamps
docker logs -t --tail 50 container-name
# Works for stopped containers too
docker logs container-idExit code 1 — Application crash
Check the logs for error messages.
docker logs container-name 2>&1 | tail -30Common causes:
- Missing environment variable:
Error: DATABASE_URL is not defined - Port conflict:
Error: listen EADDRINUSE :::3000 - Missing file/config:
No such file or directory
# Check environment variables
docker inspect container-name | grep -A 20 '"Env"'
# Inspect inside a one-off container
docker run --rm -it --env-file .env image-name /bin/shExit code 137 — OOM kill
# Check whether it was OOM-killed
docker inspect container-name | grep -i oom
# "OOMKilled": true means OOM
# Check memory usage
docker stats --no-stream container-name# Increase the memory limit (docker run)
docker run -m 512m image-name
# docker-compose.yml
# services:
# myapp:
# mem_limit: 512mCheck and change the restart policy
# Check the current restart policy
docker inspect container-name | grep -A 3 'RestartPolicy'| Policy | Behavior |
|---|---|
no | Do not restart (default) |
always | Always restart (regardless of exit code) |
on-failure | Restart only on non-zero exit |
unless-stopped | Always restart until manually stopped |
# If restart loops are the problem, switch the policy to on-failure
docker update --restart=on-failure:5 container-name
# Stop after 5 attempts
# Stop completely
docker update --restart=no container-name
docker stop container-nameDebugging — start the container manually
# Ignore the entrypoint and drop into a shell (inspect the cause directly)
docker run --rm -it --entrypoint /bin/sh image-name
# Enter a shell with the existing container's env
docker run --rm -it $(docker inspect container-name --format '{{range .Config.Env}}-e {{.}} {{end}}') --entrypoint /bin/sh image-nameFAQ
Q. docker ps keeps showing Restarting. Where should I start?
A. Start with docker logs <container> to see the output just before exit. Then get the exit code with docker inspect <container> --format '{{.State.ExitCode}}'. 137 = OOM (out of memory), 1 or 2 = application exception, 126 or 127 = missing executable or a permission problem. If the restart policy is always, the container will loop forever every time the app dies, so switch to --restart=no first so you can capture logs.
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Questions & answers
Ask a question about this guide. We'll review and reply.