What is the syntax for ELASTICSEARCH_HOSTS in docker-compose?

Viewed 7480

Trying to figure out Kibana's ELASTICSEARCH_HOSTS syntax, but I receive either:

kib01     |  FATAL  Error: [config validation of [elasticsearch].hosts]: types that failed validation:
kib01     | - [config validation of [elasticsearch].hosts.0]: expected URI with scheme [http|https].
kib01     | - [config validation of [elasticsearch].hosts.1]: could not parse array value from json input

from Kibana itself or:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.kibana.environment.ELASTICSEARCH_HOSTS contains ["http://es01:9200", "http://es02:9200", "http://es03:9200", "http://es04:9200"], which is an invalid type, it should be a string, number, or a null

from Docker compose.

My latest iteration is:

environment:
  ELASTICSEARCH_HOSTS=["http://es01:9200", "http://es02:9200", "http://es03:9200", "http://es04:9200"]

I have also tried:

environment:
  - ELASTICSEARCH_HOSTS: '["http://es01:9200", "http://es02:9200", "http://es03:9200", "http://es04:9200"]'

I tried turning that into a list:

environment:
  ELASTICSEARCH_HOSTS:
    - "<host1>"
    - "<host2>"

I tried removing quotes in various places in the above variation and various combinations on the list.

I also tried a combination from the official documentation using both : and =

with ELASTICSEARCH_HOST = http://es01:9200, http://es02:9200...

All have been rejected. Does anyone know the magic syntax to get this to work?

Updated List of failures:

  ELASTICSEARCH_HOSTS: ['http://es01:9200','http://es02:9200','http://es03:9200','http://es04:9200']
  ELASTICSEARCH_HOSTS="['http://es01:9200','http://es02:9200','http://es03:9200','http://es04:9200']"
  - ELASTICSEARCH_HOSTS=['http://es01:9200','http://es02:9200','http://es03:9200','http://es04:9200']
  - ELASTICSEARCH_HOSTS="["http://es01:9200","http://es02:9200","http://es03:9200","http://es04:9200"]"
  ELASTICSEARCH_HOSTS:
    - "<host1>"
    - "<host2>"
1 Answers

There are some things to note to solve your problem:

  • In docker-compose, your environment variables must be written as an object, or an array:
# A native yaml approach to define key-value objects
environment:  
  KEY1: VAL1
  KEY2: VAL2
# OR
# Some special way for compose yaml parser
# that can split key and value from a "KEY=VAL" string
environment:  
  - KEY1=VAL1
  - KEY2=VAL2
  • The value of an environment variable must be a string (the above example), a number, or null (empty value). Note that [foo, bar] is parsed as a list in the first format (and if you want it to be parsed as a string, you need to wrap it inside quotation marks), but the second format parses it as a string.

  • In this forum question, there is an example to how pass multiple elasticsearch hosts as an environment variable (ELASTICSEARCH_HOSTS).

So this must be a valid example that docker-compose and Kibana can both understand:

environment:
  ELASTICSEARCH_HOSTS: '["http://es01:9200","http://es02:9200","http://es03:9200","http://es04:9200"]'
# OR
environment:
  - ELASTICSEARCH_HOSTS=["http://es01:9200","http://es02:9200","http://es03:9200","http://es04:9200"]
Related