<p>I'm using Search Guard plugin to secure an elasticsearch cluster composed of multiple nodes.
Here is my Dockerfile:</p>

<pre><code>#!/bin/sh
FROM docker.elastic.co/elasticsearch/elasticsearch:5.6.3

USER root

# Install search guard
RUN bin/elasticsearch-plugin install --batch com.floragunn:search-guard-5:5.6.3-16 \
    &amp;&amp; chmod +x \
        plugins/search-guard-5/tools/hash.sh \
        plugins/search-guard-5/tools/sgadmin.sh \
        bin/init_sg.sh \
    &amp;&amp; chown -R elasticsearch:elasticsearch /usr/share/elasticsearch

USER elasticsearch
</code></pre>

<p>To initialize SearchGuard (create internal users and assign roles). I need to run the script <code>init_sg.sh</code> after the container startup. 
Here is the problem: Unless elasticsearch is running, the script will not initialize any security index. </p>

<p>The script's content is :</p>

<pre><code>sleep 10
plugins/search-guard-5/tools/sgadmin.sh -cd config/ -ts config/truststore.jks -ks config/kirk-keystore.jks -nhnv -icl
</code></pre>

<p>Now, I just run the script manually after the container startup but since I'm running it on Kubernetes.. Pods may get killed or fail and get recreated automatically for some reason. In this case, the plugin have to be initialized automatically after the container startup! </p>

<p>So how to accomplish this? Any help or hint would be really appreciated.</p>

<p>The image itself has an entrypoint <code>ENTRYPOINT ["/run/entrypoint.sh"]</code> specified in the Dockerfile. You can replace it by your own script. So for example create a new script, mount it and first call <code>/run/entrypoint.sh</code> and then wait for start of elasticsearch before running your <code>init_sg.sh</code>.</p>
