How to make Dockerfile for Elasticsearch | How to Install and Configure Elasticsearch with the Docker


Elasticsearch is a popular open-source search and analytics engine for use cases such as log analytics, real-time application monitoring, and click stream analytics.

Elasticsearch  is a search server based on Lucene. Elasticsearch is developed in Java and is released as open source under the terms of the Apache License. Elasticsearch is the most popular enterprise search engine followed by “Apache Solr”, also based on Lucene.

To know more please click here

So here in this article we have to learn that how to write Dockerfile for Elasticsearch v2.4.5  and build Elasticsearch’s Docker image and run a Docker Container.

For the above things we have to follow these steps and assume that you have Linux OS in your system and Docker engine are running.

  1. Make a Docker file with Ubuntu 16.04 Base image
  2. Build Image from Dockerfile
  3. Run Docker Container
  4. To configure your elasticsearch server execute the container and configure as per your requirements


# vim    Dockerfile

#vesrion  0.0.1

FROM ubuntu:16.04
MAINTAINER Gaurav Srivastava

#some_ important _library
RUN apt-get update && apt-get install wget build-essential gcc make -y
RUN apt-get install common-software-properties  -y

RUN apt-get install default-jdk -y
RUN apt-get install openjdk-8-jre -y
RUN apt-get update
RUN wget -O - | apt-key add -
RUN echo  "deb stable main" | tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
RUN apt-get update &&  apt-get install elasticsearch -y
RUN apt-get install git -y
RUN apt-get install python2.7 -y
RUN apt-get install vim  -y


RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:password' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

#SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s* optional' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
CMD ["/usr/sbin/sshd", "-D"]
RUN service ssh restart

:wq (Save an Exit ).
  1. Build Image from Dockerfile

Example: # docker  build  –t  <tag= repo/imagename>

# docker   build –t  linux-point/elasticsearch   .

# docker    images

REPOSITORY                 TAG     IMAGE ID       CREATED       SIZE
linux-point/elasticseacrh  latest  3739ab6g6f4e   10sec ago     1.54GB
  1. Run Docker Container

Example: # docker run –it    -p   --name   -d     

# docker  run  –it  -p 9200:9200 --name elasticsearch-server   –d  3739ab6g6f4e   /bin/bash

Now we can see that our elasticsearch-server are running.

# docker ps  

CONTAINER ID       IMAGE             COMMAND    CREATED     STATUS     PORTS                                                    NAMES                          
f8249c02deae     3739ab6g6f4e    "/bin/bash"   5 mins ago  Up 5min   22/tcp,>9200/tcp,>80/tcp  elasticsearch-sever

# docker     exec  –it   elasticsearch-sever     bash

  1. To configure your elasticsearch server execute the container and configure as per your requirement.

There are basic configuration shown as example

root@f8249c02deae:~# vim  /etc/elasticsearch/elasticsearch.yml

Uncomment these lines if not available add these.

# Use a descriptive name for your cluster: linux-point-development

# -------------------- Node -----------------
# Use a descriptive name for the node: Tech-Blog
# -------------- Memory -------------------------
# Lock the memory on startup:
 bootstrap.memory_lock: true
# -------------- Network -------------------
# Set the bind address to a specific IP (IPv4 or IPv6):
 network.publish_host: localhost

# network.bind_host:
# Set a custom port for HTTP:
 http.port: 9200-9300


root@f8249c02deae:~#  service  elasticsearch    start

Test the elasticsearch server are running

root@f8249c02deae:~#  curl http://localhost:9200

  "name" : "Tech-Blog",
 "cluster_name" : "linux-point- development ",
  "cluster_uuid" : "huIY_z9fQnWhdUiQrqfyLA",
   "version" : {
     "number" : "2.4.5",
     "build_hash" : "19c13d0",
     "build_date" : "2017-07-18T20:44:24.823Z",
     "build_snapshot" : false,
     "lucene_version" : "6.6.0"
  "tagline" : "You Know, for Search"

press ctrl+D to exit from container and test from base Machine 

# curl http://localhost:9200

  "name" : "Tech-Blog",
 "cluster_name" : " linux-point- development",
  "cluster_uuid" : "huIY_z9fQnWhdUiQrqfyLA",
  "version" : {
    "number" : "2.4.5",
    "build_hash" : "19c13d0",
    "build_date" : "2017-07-18T20:44:24.823Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  "tagline" : "You Know, for Search"

Now with your Public/Private IP you can See in browser by  http://<ip>:9200 

If you are using  AWS EC2  intance  as Base Server so you have to open Port  9200 for and ::0 to anywhere in security group which is associated with your EC2 Instance.

Like and share  @Thank you! 


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s