Fixing Elasticsearch + CircleCI + Exit code 137

I recently encountered the error "Exited with code 137" on CircleCI when using it in conjunction with Elasticsearch:

The config for elasticsearch was set as so:

- image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
  environment:
    - cluster.name: elasticsearch
    - transport.host: localhost
    - network.host: 127.0.0.1
    - http.port: 9200
    - discovery.type: single-node
    - xpack.security.enabled: false

After some research, I found that I needed to add the following environment option:

  - ES_JAVA_OPTS: -Xms750m -Xmx750m

What does this do? It sets the heap size for the JVM. It defines a minimum and maximum heap size of 750 MB.

So your config would look like this:

      - image: docker.elastic.co/elasticsearch/elasticsearch:6.8.6
        environment:
          - cluster.name: elasticsearch
          - transport.host: localhost
          - network.host: 127.0.0.1
          - http.port: 9200
          - discovery.type: single-node
          - xpack.security.enabled: false
          - ES_JAVA_OPTS: -Xms750m -Xmx750m

References