Launch elasticsearch dockerfile using my own elasticsearch.yml

Solution 1:

You can specify the elasticsearch.yml with the "-Des.config" parameter.

For example:

elasticsearch -Des.config=/path/to/elasticsearch.yml

Or in your Dockerfile:

CMD ["/usr/share/elasticsearch/bin/elasticsearch", "-Des.config=/path/to/elasticsearch.yml"]

Solution 2:

In other to add your own elasticsearch configuration to your container you have a option to create a custom image.

Create a custom image is very simple, if you are familiar with Dockerfile you only need to do few things:

FROM base/elasticsearchimage
ADD elasticsearch.yml /path/to/conf/elasticsearch.yml
CMD ["/usr/share/elasticsearch/bin/elasticsearch", "-Des.config=/path/to/conf/elasticsearch.yml"]

Place both Dockerfile and elasticsearch.yml on same folder and run the following command:

On Linux:

sudo docker build -t username/elasticsearch.

Windows (via boot2docker):

docker build -t username/elasticsearch .

And after a successful build do:

docker run -d --name containername username/elasticsearch

With this you will make the configuration always available to your new containers, reducing the effort to create a cluster too.

Solution 3:

Copy the custom yml file to config directory of ES in the Dockerfile, put the yml file in the same dir with Dockerfile and build the image

FROM docker.elastic.co/elasticsearch/elasticsearch:7.6.2
COPY --chown=elasticsearch:elasticsearch ./elasticsearch.yml /usr/share/elasticsearch/config/

More could be found here

Solution 4:

If you are using docker-compose, you may add a volumes section in your docker-compose.yml file as follows:

    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true

The elsticsearch section would look like the following:

services:
  elasticsearch:
    build:
      context: elasticsearch/
      args:
        ELK_VERSION: $ELK_VERSION
    volumes:
      - type: bind
        source: ./elasticsearch/config/elasticsearch.yml
        target: /usr/share/elasticsearch/config/elasticsearch.yml
        read_only: true
      - type: volume
        source: elasticsearch
        target: /usr/share/elasticsearch/data
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_PASSWORD: changeme
    networks:
      - elk