How are environment variables handled?

Hello,

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 cluster.name=testcluster
#
# will cause Elasticsearch to be invoked with -Ecluster.name=testcluster
#
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#_setting_default_settings

declare -a es_opts

while IFS='=' read -r envvar_key envvar_value
do
    # Elasticsearch settings need to have at least two dot separated lowercase
    # words, e.g. `cluster.name`, 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
          es_opt="-E${envvar_key}=${envvar_value}"
          es_opts+=("${es_opt}")
        fi
    fi
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 cluster.name in docker.

2 Likes