Posted on

dockerfile for elasticsearch

Here’s a dockerfile to install Elasticsearch . Change the version number to match the tar ball you want to use.
# Elasticsearch Dockerfile
#
# Simple example for running ES 2.4.4

#

# Pull base image.

FROM java:8-jre

ENV ES_PKG_NAME elasticsearch-2.4.4

# Install Elasticsearch.
COPY config/$ES_PKG_NAME.tar.gz /tmp/
RUN tar -C /usr/share/ -xvzf /tmp/$ES_PKG_NAME.tar.gz && \
mkdir /var/log/elasticsearch && \
mkdir /var/lib/elasticsearch && \
mkdir /var/run/elasticsearch && \
mkdir /etc/elasticsearch && \
mv /usr/share/$ES_PKG_NAME /usr/share/elasticsearch && \
mkdir /usr/share/elasticsearch/config/scripts && \
groupadd -g 1000 elasticsearch && useradd elasticsearch -u 1000 -g 1000
COPY config/elasticsearch.yml.staging /etc/elasticsearch/elasticsearch.yml
COPY config/elasticsearch /etc/init.d/elasticsearch
COPY config/log4j2.properties /etc/elasticsearch/
COPY config/jvm.options /etc/elasticsearch/
COPY config/logging.yml /etc/elasticsearch/
RUN chown -R elasticsearch.elasticsearch /usr/share/elasticsearch && \
chown -R elasticsearch.elasticsearch /var/log/elasticsearch && \
chown -R elasticsearch.elasticsearch /var/lib/elasticsearch && \
chown -R elasticsearch.elasticsearch /var/lib/elasticsearch && \
chown -R elasticsearch.elasticsearch /var/run/elasticsearch && \
chown -R elasticsearch.elasticsearch /etc/elasticsearch && \
echo End of elasticsearch base install

# Define mountable directories.
VOLUME /data
# Define working directory.
#WORKDIR /data/elasticsearch/

COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]
# Expose ports.
# - 9200: HTTP
# - 9300: transport
EXPOSE 9200
EXPOSE 9300


This is the docker-entrypoint.sh:
#!/bin/bash
if [ "$1" = 'elasticsearch' ]; then
start-stop-daemon -d /usr/share/elasticsearch --start -u elasticsearch -c elasticsearch --pidfile /var/run/elasticsearch/elasticsearch.pid --exec /usr/share/elasticsearch/bin/elasticsearch -- -p /var/run/elasticsearch/elasticsearch.pid --default.path.home=/usr/share/elasticsearch --default.path.logs=/var/log/elasticsearch/ --default.path.data=/var/lib/elasticsearch --default.path.conf=/etc/elasticsearch/
# then assume that user wants to run his own process,
# for example a `bash` shell to explore this image
else
exec "$@"
fi

and these files are in config and are taken from the elasticsearch package:
config/
elasticsearch
elasticsearch-2.4.4.tar.gz
elasticsearch.yml.staging
jvm.options
log4j2.properties
logging.yml