Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install ElasticSeach plugins using docker compose

I have a docker-compose.yml file with an elastic search image:

elasticsearch:
  image: elasticsearch
  ports:
    - "9200:9200"
  container_name: custom_elasticsearch_1

If I want to install additional plugins like the HQ interface or the attachment-mapper I have to do a manual installation with the following commands:

$ docker exec custom_elasticsearch_1 plugin install royrusso/elasticsearch-HQ
$ docker exec custom_elasticsearch_1 plugin install mapper-attachments

Is there a way to install them automatically when I run the docker-compose up command?

like image 346
iamdeit Avatar asked Sep 25 '16 20:09

iamdeit


3 Answers

Here is a blog post by Elastic pertaining to exactly that! You need to use a Dockerfile which executes commands to extend an image. Your Dockerfile will look something like this:

FROM custom_elasticsearch_1

RUN elasticsearch-plugin install royrusso/elasticsearch-HQ
like image 108
fylie Avatar answered Oct 23 '22 17:10

fylie


Inspired by @NickPridorozhko's answer, but updated and tested with elasticsearch^7.0.0 (with docker stack / swarm), example with analysis-icu:

elasticsearch:
  image: docker.elastic.co/elasticsearch/elasticsearch:7.3.0
  user: elasticsearch
  command: >
    /bin/sh -c "./bin/elasticsearch-plugin list | grep -q analysis-icu 
    || ./bin/elasticsearch-plugin install analysis-icu; 
    /usr/local/bin/docker-entrypoint.sh"
  ...

The main difference are the updated commands for ^7.0.0, and the use of the docker entrypoint instead of ./bin/elasticsearch (in a stack's context, you'd get an error related to a limit of spawnable processes).

like image 37
Bigood Avatar answered Oct 23 '22 19:10

Bigood


This works for me. Install plugin before and then continue with starting the elasticsearch.

elasticsearch:
  image: elasticsearch
  command:
    - sh
    - -c
    - "plugin list | grep -q plugin_name || plugin install plugin_name;
       /docker-entrypoint.sh elasticsearch"
like image 5
Nick Pridorozhko Avatar answered Oct 23 '22 17:10

Nick Pridorozhko