Likely causes
- •The container hit its memory limit and the OOM killer stopped it. Run docker inspect --format '{{.State.OOMKilled}}' <container>. If it prints true, this is the cause. A memory limit set with --memory or mem_limit in Compose makes this very common.
- •The whole host ran out of memory. The container has no limit, but the kernel killed it to free RAM. OOMKilled may show false here. Check the kernel log with dmesg -T | grep -i 'killed process' and look for your process name.
- •A memory leak or a traffic spike in the app. Memory climbs over time until the kill, or the kill lines up with a busy period or a deploy. docker stats shows usage rising toward the limit.
- •docker stop or docker compose down timed out. Docker sends SIGTERM, waits 10 seconds by default, then sends SIGKILL. If the app ignores SIGTERM, you see 137 on every stop. OOMKilled is false and the kernel log is clean.
- •Someone or something sent SIGKILL. A manual docker kill, kill -9, a deploy script or an orchestrator can do this. Check docker events and your shell or CI history for the container name.
How to fix it
1. Check whether Docker recorded an OOM kill
This separates memory problems from manual or timeout kills. OOMKilled true points to memory. ExitCode 137 with OOMKilled false points to the host OOM killer, a stop timeout or a manual kill.
docker inspect --format 'OOMKilled={{.State.OOMKilled}} ExitCode={{.State.ExitCode}}' <container>2. Look for kernel OOM kills on the host
This catches host-wide memory pressure that Docker does not flag. On systemd distributions you can use journalctl instead of dmesg.
dmesg -T | grep -i -E 'out of memory|killed process' # or journalctl -k --no-pager | grep -i -E 'out of memory|killed process'3. Watch live memory use against the limit
If usage sits near the limit, raise the limit or reduce what the app uses. If it climbs steadily, suspect a leak.
docker stats --no-stream docker inspect --format '{{.HostConfig.Memory}}' <container>4. Raise the memory limit or free memory on the host
A value of 0 means no limit. docker update changes a running container without recreating it, and it does not restart the container. Set --memory-swap equal to or above --memory. Also make sure the host has enough free RAM, or the host OOM killer will still act. For Compose, set mem_limit (or deploy.resources.limits.memory) in your file and recreate the service.
docker update --memory 1g --memory-swap 2g <container>5. Fix the app's memory use
Cap the runtime's own heap so it stays under the container limit, for example NODE_OPTIONS=--max-old-space-size=768 for Node or -Xmx for Java. Lower worker or queue concurrency. Look for leaks if usage rises without traffic growth.
6. If the exit happens on stop, handle SIGTERM
Make sure the app is PID 1 or that an init process forwards signals. Use the exec form of CMD (a JSON array) so the shell does not swallow SIGTERM. You can also add init: true in Compose, or --init with docker run. If shutdown needs more time, raise the grace period. Note that this command stops the container.
docker stop --time 30 <container>7. Check for manual or scripted kills
Review the Docker event stream for kill events on this container, then check cron jobs, deploy scripts and CI for kill -9 or docker kill.
docker events --since 1h --filter container=<container> --filter event=kill --filter event=oom8. Restart the container with the new settings
Warning: this interrupts the service for a few seconds. Do it in a quiet period. With Compose, recreate the service so file changes apply.
docker compose up -d --force-recreate <service>
Confirm it is fixed
Confirm the container is running, not restarting, that no new OOM kill is recorded, and that memory stays below the limit under normal load. Watch it for a full busy period, not just a minute. Good output shows Status running, OOMKilled false, RestartCount not rising, and no new kill lines in the kernel log.
docker inspect --format 'Status={{.State.Status}} OOMKilled={{.State.OOMKilled}} Restarts={{.RestartCount}}' <container>
docker stats --no-stream <container>How Opservo catches it early
Opservo's agent discovers every Docker container on the server and flags one that keeps restarting, so a crash loop on code 137 shows up early. It also clusters container logs into error patterns and counts out-of-memory kills in the kernel log. Any OOM kill since boot is a critical finding in the server's health score.
Last updated 2026-11-30.