Install Elastic Search Plugins Through Docker

L

ately I have been using Docker for development. It makes it really easy to stand up services and package entire stacks for projects. Most recently, I set up an elastic search instance, and the first thing I wanted to do was install the insanely helpful Head and Big Desk plugins. The official elastic search Dockerfile is just elastic search, no plugins. And of course, containers are pretty much a black box. Every time it restart, everything is back to square one. Luckily, The image exposes a volume for persistent data, and that is all we really need to have to install plugins. Here is how You can do that.

Install Elasticsearch Container

First we need to pull the docker image and set up a directory where our plugins and search data will go.

docker pull dockerfile/elasticsearch  
mkdir -p $HOME/data/plugins  

Configuration

Next we need a create a a config file for elastic search to tell it where to look for plugins.

touch $HOME/data/elasticsearch.yml  

Edit your config file to include the head plugin. The plugins path should point to the plugins directory of the volume path inside the container, not on your local host computer.

path:  
  plugins: /data/plugins

Install Plugins

To load the Head admin plugin, we can just use the plugin binary in the container rather the running the default command to start the server. You may install any other plugins for your search instance in a similar manner.

docker run -v $HOME/data:/data dockerfile/elasticsearch /elasticsearch/bin/plugin -i mobz/elasticsearch-head  

Run The Container

Run the container mapping your data directory, expose ports 9200 & 9300, and point it at your local configuration yaml file.

docker run -d -p 9200:9200 -p 9300:9300 -v $HOME/data:/data dockerfile/elasticsearch /elasticsearch/bin/elasticsearch  

And you are done. You can open up http://localhost:9200/_plugins/head in your browser! Now you can stop, start and rebuild your container and you will still have your plugins and data.

elasticsearch docker plugins