How are environment variables handled?


I see in the examples given through the documentation that you can define environment variables like cluster.initial_master_nodes or discovery.seed_host

How do these variables get handled inside the container? Are they automatically resolved by Elasticsearch or do they need to be appended to the elasticsearch.yml configuration file through a manual action?

Yes they are added by docker entrypoint

Here to mos important lines:

# Parse Docker env vars to customize Elasticsearch
# e.g. Setting the env var
# will cause Elasticsearch to be invoked with
# see

declare -a es_opts

while IFS='=' read -r envvar_key envvar_value
    # Elasticsearch settings need to have at least two dot separated lowercase
    # words, e.g. ``, except for `processors` which we handle
    # specially
    if [[ "$envvar_key" =~ ^[a-z0-9_]+\.[a-z0-9_]+ || "$envvar_key" == "processors" ]]; then
        if [[ ! -z $envvar_value ]]; then
done < <(env)

So pay attention to use only valid ES options as environment variables.

1 Like

Thank you for answering Aparo.

I have 2 questions from here:

1- Where can I find the list of all valid ES options as environment variables?
2- In case the same variable is defined as an environment variable and in the same time in the elasticsearch.yml file, which one has priority?

  1. you need to look to the ES documentation, but everything you put on elasticsearch.yml is a valid variable. They are simple key/value pairs.

  2. I’m 90% sure that ENV should have priority. I have no time now to check the code of Bootstrap and Environment class.
    Just try with in docker.