How to install Elasticsearch plugins with docker container?

I am a newbie in Docker, I want to install plugins in my container of elasticsearch, in this case they are:

  • analysis-icu
  • analysis-phonetic

I know that in a traditional way it would be like this:

  • /usr/share/elasticsearch in this directory

sudo bin/elasticsearch-plugin install analysis-icu

sudo bin/elasticsearch-plugin install analysis-phonetic

➜ docker ps   
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                            NAMES
f7aaead8fd09        elasticsearch:7.0.1   "/usr/local/bin/dock…"   2 days ago          Up 10 minutes       0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch

Any ideas or suggestions?

If you are using elasticsearch 6, the commands to install plugins are a bit different than in @asktyagi's answer. Put this in your Dockerfile

FROM elasticsearch:6.8.3
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu && \ 
    /usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-phonetic

Then

docker build -t elasticsearch .

If you are using Dockerfile try something link below

FROM elasticsearch:2
RUN /usr/share/elasticsearch/bin/plugin install --batch <plugin>

After that you can build

$ docker build -t elasticsearch-aws .

Here is good reference https://www.elastic.co/blog/elasticsearch-docker-plugin-management .

If you want to install plugin directly from docker follow below steps.

  1. Login to docker docker exec -it <id> /bin/bash
  2. Find elasticsearch home dir and execute your command to install plugin.

But remember this way it is not persistent.