DEV Community

Cover image for Dockerfile for Elasticsearch

Posted on • Updated on

Dockerfile for Elasticsearch

Elasticsearch is a distributed, free and open search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured.

Elasticsearch is the central component of the Elastic Stack, a set of free and open tools for data ingestion, enrichment, storage, analysis, and visualization.

It is considerably easier and faster to run elasticsearch in a container than to install it on a host server.

1)Create a docker file and add the below contents.

# vim Dockerfile

FROM centos:7
RUN useradd -ms /bin/bash elasticsearch
RUN yum -y install java-1.8.0-openjdk-devel
RUN yum -y install wget
RUN wget
RUN rpm -ivh elasticsearch-5.5.0.rpm
RUN mkdir /usr/share/elasticsearch/config
RUN cp -R /usr/share/elasticsearch/* /home/elasticsearch/
COPY elasticsearch.yml /home/elasticsearch/config/
COPY /home/elasticsearch/config/
RUN chown -R elasticsearch:elasticsearch /home/elasticsearch/*
WORKDIR /home/elasticsearch
USER elasticsearch
CMD ["/home/elasticsearch/bin/elasticsearch"]
Enter fullscreen mode Exit fullscreen mode

elasticsearch.yml and are the updated files with the configurations needed for our elasticsearch.Place both files in the same directory where dockerfile exists.

2) Build docker image
NB: be in the directory where dockerfile exists
docker build -t elasticsearh .
"elasticsearch is the image name"

3) Create docker container
# docker images #to get the docker image id
# docker run -d -P 9200:9200 -P 9300:9300 --name elastic <image id>

4) check container status
# docker ps

Play with docker🥂

Top comments (0)