0
FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.2
USER root
WORKDIR /usr/share/elasticsearch/

ENV ES_HOSTNAME elasticsearch
ENV ES_PORT 9200

RUN chown elasticsearch:elasticsearch config/elasticsearch.yml
RUN chown -R elasticsearch:elasticsearch data
# install security plugin

RUN bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.5.2-16
COPY ./safe-guard/install_demo_configuration.sh plugins/search-guard-5/tools/

COPY ./safe-guard/init-sgadmin.sh plugins/search-guard-5/tools/
RUN chmod +x plugins/search-guard-5/tools/init-sgadmin.sh

ADD ./run.sh .
RUN chmod +x run.sh


RUN chmod +x plugins/search-guard-5/tools/install_demo_configuration.sh

RUN ./plugins/search-guard-5/tools/install_demo_configuration.sh -y

RUN chmod +x sgadmin_demo.sh

RUN  yum install tree -y

#RUN curl -k -u admin:admin https://localhost:9200/_searchguard/authinfo

RUN usermod -aG wheel elasticsearch


USER elasticsearch

EXPOSE 9200

#ENTRYPOINT ["nohup",  "./run.sh", "&"]

ENTRYPOINT ["/usr/share/elasticsearch/run.sh"]

#CMD ["echo", "hello"]

Once I add either CMD or Entrypoint - "Container is exited with code 0"

#!/bin/bash

exec $@

If I comment ENTRYPOINT or CMD - all is great.

What I am doing wrong???

Svitlana
  • 2,324
  • 4
  • 22
  • 31

1 Answers1

1

If you take a look at official 5.6.9 elasticsearch Dockerfile, you will see the following at the bottom:

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]

If you do not know the difference between CMD and ENTRYPOINT, read this answer.

What you're doing is you're overwriting those two instructions with something else. What you really need is to extend CMD. What I usually do in my images, I create an sh script and combine different things I need and then indicate the script for CMD. So, you need to run sgadmin_demo.sh, but you need to wait for elasticsearch first. Create a start.sh script:

#!/bin/bash
elasticsearch
sleep 15
sgadmin_demo.sh

Now, add your script to your image and run it on CMD:

FROM: ...
...
COPY start.sh /tmp/start.sh
CMD ["/tmp/start.sh"]

Now it should be executed once you start a container. Don't forget to build :)

Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66