3

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
2
  • Just curious why docket hub's elastisesrch image was not used? Commented Mar 14, 2019 at 6:37
  • 1
    Because, I want to run my system on ubuntu. Is not there only centos in the docker hub? Commented Mar 14, 2019 at 9:27

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

It stops after the RUN line it was started, even -- later RUN commands in the same Dockerfile won't see it running.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.