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?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.