2

I have been trying to make the searchguard setup script init_sg.sh to run after elasticsearch automatically. I don't want to do it manually with docker exec. Here's what I have tried.

entrypoint.sh:

#! /bin/sh
elasticsearch
source init_sg.sh

Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.0

COPY config/ config/
COPY bin/ bin/

# Search Guard plugin
# https://github.com/floragunncom/search-guard/wiki
RUN elasticsearch-plugin install --batch com.floragunn:search-guard-6:6.1.0-20.1 \
    && chmod +x \
        plugins/search-guard-6/tools/hash.sh \
        plugins/search-guard-6/tools/sgadmin.sh \
    && chown -R elasticsearch config/sg/ \
    && chmod -R go= config/sg/


#  This custom entrypoint script is used instead of 
# the original's /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["bash","-c","entrypoint.sh"]

However, it'd throw cannot run elasticsearch as root error:

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

So I guess I cannot run elasticsearch directly in entrypoint.sh, which is confusing because there's no problem when the Dockerfile is like this:

FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.0

COPY config/ config/
COPY bin/ bin/
....
CMD ["elasticsearch"]

This thread's accepted answer doesn't work. There's no "/run/entrypoint.sh" in the container.

Solution:

Finally I've managed to get it done. Here's my custom entrypoint script that will run the searchguard setup script automatically:

source init_sg.sh

while [ $? -ne 0 ]; do
   sleep 10
   source init_sg.sh
done &

/bin/bash -c "source /usr/local/bin/docker-entrypoint.sh;"

If you have any alternative solutions, please feel free to answer.

srgbnd
  • 5,404
  • 9
  • 44
  • 80
RedGiant
  • 4,444
  • 11
  • 59
  • 146
  • Have you tried removing last line ENTRYPOINT ["bash","-c","entrypoint.sh"] - from Dockerfile and then just run your post install script in Dockerfile using RUN command like 'RUN mkdir -p /var/www/html' – Prateek Jain May 25 '18 at 13:07
  • @techtrainer the setup script has to be executed after elasticsearch starts up. `RUN` would actually run the command during the build, which isn't what I'm looking for. – RedGiant May 25 '18 at 13:13
  • see also https://github.com/deviantony/docker-elk/tree/searchguard – Search Guard May 25 '18 at 18:45

0 Answers0