Elasticsearch with Docker

Wolf
3 min readJan 15
Photo by Chris Ried on Unsplash

We have available online a lot of snippets that we can use if we want to start a container with Elasticsearch with base configuration in our computer.

But if we want a Elasticsearch with synonyms files and custom configuration? Can be a little more difficult to find a snippet with all the details. Having that in mind I decide to make a more detailed post with custom configurations for our docker container.

Requirements:

  • Docker already installed in our system
  • Login in Docker
  • Visual Studio code or some editor from your preference to create and edit the files

First, the Dockerfile:

  • Create a new file called Dockerfile without extension where we will set all the steps that we need to customize our Elasticsearch installation.
  • Decide what will be the version that we want to use. For the example, we will be using the 8.6.0.
  • The first line will be:
From docker.elastic.co/elasticsearch/elasticsearch:8.6.0 as elasticsearch
  • Add synonym files — the synonyms_path should be the path in the host for the folder containing synonym's files inside the same folder where we have the Dockerfile:
ADD ./{synonyms_path}/ /usr/share/elasticsearch/config/
VOLUME ["/usr/share/elasticsearch/config/"]
  • Add the configurations — the config_path should be the path in the host for the folder containing the config file inside the same folder where we have the Dockerfile:
ADD ./{config_path}/ /usr/share/elasticsearch/config/
VOLUME ["/usr/share/elasticsearch/config/"]
  • Add plugins — the plugins_path should be the path in the host for the folder containing the plugins inside the same folder where we have the Dockerfile:
ADD ./{plugins_path}/ /usr/share/elasticsearch/plugins/
VOLUME ["/usr/share/elasticsearch/plugins/"]

Note: all the plugins should be built for the same version of Elasticsearch that we are using: 8.6.0

  • Expose the Elasticsearch port:
EXPOSE 9200

You should have a Dockerfile like this:

Wolf

A software engineer looking for learning more and share my knowledge.