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

ELASTICSEARCH 

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

  1.  DOCKERFILE TO BUILD ELASTICSEACRH IMAGE

# 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

#Install_JAVA
RUN apt-get install default-jdk -y
RUN apt-get install openjdk-8-jre -y
RUN apt-get update
RUN wget -O - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN echo  "deb  http://packages.elastic.co/elasticsearch/2.x/debian 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

#configuration_to_PubilsOverSSH

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*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
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, 0.0.0.0:9200->9200/tcp, 0.0.0.0:9400->80/tcp  elasticsearch-sever



# docker     exec  –it   elasticsearch-sever     bash

root@f8249c02deae:~#_
  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:
 cluster.name: linux-point-development

# -------------------- Node -----------------
# Use a descriptive name for the node:
 node.name: 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.host: 127.0.0.1
 network.publish_host: localhost
 #network.bind_host: 0.0.0.0

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

:wq

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 0.0.0.0 and ::0 to anywhere in security group which is associated with your EC2 Instance.

Like and share  @Thank you! 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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