DB / Docker / 137
CRITICAL

Docker Container Terminated (Out of Memory)

Exit Code 137 indicates that a Docker container was terminated by the operating system's OOM (Out Of Memory) killer. This happens when the container attempts to use more memory than is available to it, either globally on the host or within its configured memory limits.

Common Causes

  • Container process consumed more memory than allocated by Docker's memory limits.
  • Host system ran out of memory, leading to the OOM killer terminating processes, including the Docker container.
  • Memory leak within the application running inside the container.
  • Incorrectly configured memory limits for the Docker container.
  • Sudden spike in memory usage due to high load or specific operations.

How to Fix

1 Increase Container Memory Limits

Allocate more memory to the container using Docker's `--memory` or `-m` flag when running or updating the container.

BASH
$ docker run -d --memory="2g" --name my-app my-image docker update --memory="2g" my-app

2 Optimize Application Memory Usage

Analyze and optimize the application running inside the container to reduce its memory footprint. This might involve code refactoring, using more efficient data structures, or configuring garbage collection settings.

BASH
$ (Requires application-level changes and profiling tools)

3 Increase Host System Memory

If the host system itself is consistently running out of memory, consider upgrading the physical RAM or reducing the number of running containers/processes on the host.

BASH
$ (Requires hardware or system-level changes)

4 Monitor Memory Usage

Use Docker stats or other monitoring tools to track container memory usage over time and identify patterns or spikes that lead to OOM conditions.

BASH
$ docker stats <container_name_or_id>

5 Check for Memory Leaks

Profile the application within the container to identify and fix any memory leaks that might be causing gradual memory consumption.

BASH
$ docker exec -it <container_name_or_id> /bin/bash # Then use tools like 'top', 'htop', or language-specific profilers