sjpark
sjpark

Reputation: 91

Running Elasticsearch with Docker

I installed Elasticsearch in my image based on ubuntu:16.04.

And start the service using

RUN service elasticsearch start

but, it was not started.

If I go into the container and run it, it starts.

I want to run the service and dump the index when I create the image, below is a part of my Dockerfile.

How do I start Elasticsearch in the Dockerfile?

#install OpenJDK-8
RUN apt-get update && apt-get install -y openjdk-8-jdk && apt-get install -y ant && apt-get clean

RUN apt-get update && apt-get install -y ca-certificates-java && apt-get clean
RUN update-ca-certificates -f

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME

#download ES
RUN wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
RUN apt-get install -y apt-transport-https
RUN echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | tee -a /etc/apt/sources.list.d/elastic-6.x.list
RUN apt-get update && apt-get install -y elasticsearch

RUN service elasticsearch start

Upvotes: 3

Views: 1912

Answers (2)

ozlevka
ozlevka

Reputation: 2146

I don't know why not take official oss image, but, this Docker file based on Debian work:

FROM java:8-jre

ENV ES_NAME=elasticsearch \
        ELASTICSEARCH_VERSION=6.6.1
ENV ELASTICSEARCH_URL=https://artifacts.elastic.co/downloads/$ES_NAME/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz

RUN apt-get update && apt-get install -y --assume-yes openssl bash curl wget \
    && mkdir -p /opt \
    && echo '[i] Start create elasticsearch' \
    && wget -T 15 -O /tmp/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz $ELASTICSEARCH_URL \
    && tar -xzf /tmp/$ES_NAME-$ELASTICSEARCH_VERSION.tar.gz -C /opt/ \
    && ln -s /opt/$ES_NAME-$ELASTICSEARCH_VERSION /opt/$ES_NAME \
    && useradd elastic \
    && mkdir -p /var/lib/elasticsearch /opt/$ES_NAME/plugins /opt/$ES_NAME/config/scripts \
    && chown -R elastic /opt/$ES_NAME-$ELASTICSEARCH_VERSION/


ENV PATH=/opt/elasticsearch/bin:$PATH

USER elastic

CMD [ "/bin/sh", "-c", "/opt/elasticsearch/bin/elasticsearch --E cluster.name=test --E network.host=0 $ELASTIC_CMD_OPTIONS" ]

I believe most of the commands you'll be able to use on Ubuntu.

Don't forget to run sudo sysctl -w vm.max_map_count=262144 on your host

Upvotes: 1

Maroun
Maroun

Reputation: 95948

The RUN command executes only during the build phase. It stops after the build is completed. You should use CMD (or ENTRYPOINT) instead:

CMD service elasticsearch start && /bin/bash

It's better wrapping the starting command in your own file and then only execute the file:

CMD /start_elastic.sh

Upvotes: 3

Related Questions