Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing ES_JAVA_OPTS variable with spaces when using docker compose

I'm trying to run Elasticsearch using docker compose but I'm not sure how to correctly pass the ES_JAVA_OPTS="-Xms512m -Xmx512m" environmental variable. I've tried lots of combinations of single and double quotes but they all result in: Error: Could not find or load main class "-Xms512m.

My docker-compose config is:

elasticsearch:
  image: "docker.elastic.co/elasticsearch/elasticsearch:5.4.3"
  ports:
   - "6379:6379"
  environment:
   - "http.host=0.0.0.0"
   - "transport.host=127.0.0.1"
   - "xpack.security.enabled=false"
   - 'ES_JAVA_OPTS="-Xms512m -Xmx512m"'

This environmental variable works just fine when running the container directly with:

docker run --detach \
  --name elasticsearch \
  --publish 9200:9200 \
  --env "http.host=0.0.0.0" \
  --env "transport.host=127.0.0.1" \
  --env "xpack.security.enabled=false" \
  --env "ES_JAVA_OPTS=""-Xms512m -Xmx512m""" \
  docker.elastic.co/elasticsearch/elasticsearch:5.4.3

What am I missing here?

like image 252
Nathan Baulch Avatar asked Jul 05 '17 12:07

Nathan Baulch


1 Answers

According to https://github.com/docker/compose/issues/2854, it's an issue with how docker compose will parse your env variables.

If you switch to yaml map instead of list, it should work:

elasticsearch:
  image: "docker.elastic.co/elasticsearch/elasticsearch:5.4.3"
  ports:
    - "6379:6379"
  environment:
    http.host: 0.0.0.0
    transport.host: 127.0.0.1
    xpack.security.enabled: "false"
    ES_JAVA_OPTS: -Xms512m -Xmx512m
like image 73
keymone Avatar answered Nov 15 '22 05:11

keymone