Configure Elasticsearch with Docker
Self Managed
When you run in Docker, the Elasticsearch configuration files are loaded from /usr/share/elasticsearch/config/
.
To use custom configuration files, you bind-mount the files over the configuration files in the image.
You can set individual Elasticsearch configuration parameters using Docker environment variables. The sample compose file and the single-node example use this method. You can use the setting name directly as the environment variable name. If you can't do this, for example because your orchestration platform forbids periods in environment variable names, then you can use an alternative style by converting the setting name as follows:
- Change the setting name to uppercase
- Prefix it with
ES_SETTING_
- Escape any underscores (
_
) by duplicating them - Convert all periods (
.
) to underscores (_
)
For example, -e bootstrap.memory_lock=true
becomes -e ES_SETTING_BOOTSTRAP_MEMORY__LOCK=true
.
You can use the contents of a file to set the value of the ELASTIC_PASSWORD
or KEYSTORE_PASSWORD
environment variables, by suffixing the environment variable name with _FILE
. This is useful for passing secrets such as passwords to Elasticsearch without specifying them directly.
For example, to set the Elasticsearch bootstrap password from a file, you can bind mount the file and set the ELASTIC_PASSWORD_FILE
environment variable to the mount location. If you mount the password file to /run/secrets/bootstrapPassword.txt
, specify:
-e ELASTIC_PASSWORD_FILE=/run/secrets/bootstrapPassword.txt
You can override the default command for the image to pass Elasticsearch configuration parameters as command line options. For example:
docker run <various parameters> bin/elasticsearch -Ecluster.name=mynewclustername
While bind-mounting your configuration files is usually the preferred method in production, you can also create a custom Docker image that contains your configuration.
Create custom config files and bind-mount them over the corresponding files in the Docker image. For example, to bind-mount custom_elasticsearch.yml
with docker run
, specify:
-v full_path_to/custom_elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
If you bind-mount a custom elasticsearch.yml
file, ensure it includes the network.host: 0.0.0.0
setting. This setting ensures the node is reachable for HTTP and transport traffic, provided its ports are exposed. The Docker image’s built-in elasticsearch.yml
file includes this setting by default.
The container runs Elasticsearch as user elasticsearch
using uid:gid 1000:0
. Bind mounted host directories and files must be accessible by this user, and the data and log directories must be writable by this user.
By default, Elasticsearch will auto-generate a keystore file for secure settings. This file is obfuscated but not encrypted.
To encrypt your secure settings with a password and have them persist outside the container, use a docker run
command to manually create the keystore instead. The command must:
- Bind-mount the
config
directory. The command will create anelasticsearch.keystore
file in this directory. To avoid errors, do not directly bind-mount theelasticsearch.keystore
file. - Use the
elasticsearch-keystore
tool with thecreate -p
option. You’ll be prompted to enter a password for the keystore.
For example:
docker run -it --rm \
-v full_path_to/config:/usr/share/elasticsearch/config \
docker.elastic.co/elasticsearch/elasticsearch:9.0.0 \
bin/elasticsearch-keystore create -p
You can also use a docker run
command to add or update secure settings in the keystore. You’ll be prompted to enter the setting values. If the keystore is encrypted, you’ll also be prompted to enter the keystore password.
docker run -it --rm \
-v full_path_to/config:/usr/share/elasticsearch/config \
docker.elastic.co/elasticsearch/elasticsearch:9.0.0 \
bin/elasticsearch-keystore \
add my.secure.setting \
my.other.secure.setting
If you’ve already created the keystore and don’t need to update it, you can bind-mount the elasticsearch.keystore
file directly. You can use the KEYSTORE_PASSWORD
environment variable to provide the keystore password to the container at startup. For example, a docker run
command might have the following options:
-v full_path_to/config/elasticsearch.keystore:/usr/share/elasticsearch/config/elasticsearch.keystore
-e KEYSTORE_PASSWORD=mypassword
In some environments, it might make more sense to prepare a custom image that contains your configuration. A Dockerfile
to achieve this might be as simple as:
FROM docker.elastic.co/elasticsearch/elasticsearch:9.0.0
COPY --chown=elasticsearch:elasticsearch elasticsearch.yml /usr/share/elasticsearch/config/
You could then build and run the image with:
docker build --tag=elasticsearch-custom .
docker run -ti -v /usr/share/elasticsearch/data elasticsearch-custom
Some plugins require additional security permissions. You must explicitly accept them either by:
- Attaching a
tty
when you run the Docker image and allowing the permissions when prompted. - Inspecting the security permissions and accepting them (if appropriate) by adding the
--batch
flag to the plugin install command.
See Plugin management for more information.
Here’s how to resolve common errors when running Elasticsearch with Docker.
Exception in thread "main" org.elasticsearch.bootstrap.BootstrapException: java.io.IOException: Is a directory: SimpleFSIndexInput(path="/usr/share/elasticsearch/config/elasticsearch.keystore") Likely root cause: java.io.IOException: Is a directory
A keystore-related docker run
command attempted to directly bind-mount an elasticsearch.keystore
file that doesn’t exist. If you use the -v
or --volume
flag to mount a file that doesn’t exist, Docker instead creates a directory with the same name.
To resolve this error:
- Delete the
elasticsearch.keystore
directory in theconfig
directory. - Update the
-v
or--volume
flag to point to theconfig
directory path rather than the keystore file’s path. For an example, see Create an encrypted Elasticsearch keystore. - Retry the command.
Exception in thread "main" java.nio.file.FileSystemException: /usr/share/elasticsearch/config/elasticsearch.keystore.tmp -> /usr/share/elasticsearch/config/elasticsearch.keystore: Device or resource busy
A docker run
command attempted to update the keystore while directly bind-mounting the elasticsearch.keystore
file. To update the keystore, the container requires access to other files in the config
directory, such as keystore.tmp
.
To resolve this error:
- Update the
-v
or--volume
flag to point to theconfig
directory path rather than the keystore file’s path. For an example, see Create an encrypted Elasticsearch keystore. - Retry the command.