1

I am launching elasticsearch via a dockerfile found here:

https://index.docker.io/u/ehazlett/elasticsearch/

It works great. I need to define my own hosts as my environment does not support multicast of any kind.

I understand that my options are:

1) supply hosts when elasticsearch is run as a command line parameter

2) modify my elasticsearch.yml file to set the hosts.

I know how to build the yml, what I need to know is how to launch elasticsearch via docker using my own yml instead of the one in the container. Is that possible?

Thanks.

Kyle Renfro
  • 133
  • 5
Kevin
  • 133
  • 1
  • 5

4 Answers4

3

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"]
Kyle Renfro
  • 133
  • 5
1

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

D.T
  • 111
  • 2
1

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
Pat. ANDRIA
  • 111
  • 4
1

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.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
ararog
  • 111
  • 2