Elasticsearch container OOMKilled / heap too small in CI
The container was killed by the kernel out-of-memory killer because the JVM tried to reserve more heap than the container was allowed. Elasticsearch sizes heap from available memory by default, and a constrained CI container hits the limit before the node is even ready.
What this error means
The Elasticsearch service exits with status 137, the runner shows "OOMKilled", or the node dies mid-startup after logging heap allocation. Health checks never pass.
elasticsearch exited with code 137
State: Terminated
Reason: OOMKilledCommon causes
Default heap exceeds the container memory limit
Elasticsearch auto-sizes the JVM heap from the memory it sees, which can be larger than the cgroup limit imposed on the service container.
No explicit heap sizing for the CI environment
Without ES_JAVA_OPTS pinning -Xms/-Xmx, the node reserves more than the constrained runner can back, and the kernel kills it.
How to fix it
Pin the heap with ES_JAVA_OPTS
- Set a fixed, modest heap such as 512m for tests.
- Keep
-Xmsand-Xmxequal so the JVM does not grow the heap at runtime. - Ensure the container memory limit is at least double the heap for off-heap needs.
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
env:
discovery.type: single-node
ES_JAVA_OPTS: -Xms512m -Xmx512mGive the container enough memory
On OpenSearch use OPENSEARCH_JAVA_OPTS and make sure the runner has headroom above the heap for the JVM, page cache, and OS.
env:
OPENSEARCH_JAVA_OPTS: -Xms512m -Xmx512mHow to prevent it
- Always set an explicit
-Xms/-Xmxheap for CI service containers. - Provision container memory to at least twice the configured heap.
- Use the smallest heap that still passes your integration tests.