Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Elasticsearch Plugin with Request

We are attempting to run an Elasticsearch node in a Docker container. We are using the Search Guard plugin for security. However, during the install process, the plugin requires that we run a script. This script required that ElasticSearch be reachable on port 9300 when it runs. Is there a best practice for delayed scripts? We have tried sleeping before execution and the RUN and CMD Dockerfile commands.

Here is the output:

elasticsearch    | Search Guard Admin v5
elasticsearch    | Will connect to localhost:9300
elasticsearch    | ERR: Seems there is no elasticsearch running on 
localhost:9300 - Will exit

Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch:5.3.0

USER root

RUN apk update \
    && apk upgrade \
    && apk add nano

USER root

# Add the ElasticSeach config
ADD elasticsearch.yml /usr/share/elasticsearch/config/
RUN chown elasticsearch:elasticsearch /usr/share/elasticsearch/config/elasticsearch.yml

# Add the truststore
ADD keys/truststore.jks /usr/share/elasticsearch/config/
RUN chown elasticsearch:elasticsearch /usr/share/elasticsearch/config/truststore.jks

# Create the node certs
ADD gen-cert/ /usr/share/elasticsearch/gen-cert/
WORKDIR /usr/share/elasticsearch/gen-cert
RUN ./gen_node_cert.sh 0 ######### #########
RUN cp node-keystore.jks /usr/share/elasticsearch/config/

# Prep for boot!
WORKDIR /usr/share/elasticsearch/
USER elasticsearch

RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.3.0-11
RUN chmod +x -R /usr/share/elasticsearch/plugins/search-guard-5/tools/

# Run the security script on start
CMD sleep 10 && /usr/share/elasticsearch/plugins/search-guard-5/tools/sgadmin.sh \
        -cd /usr/share/elasticsearch/plugins/search-guard-5/sgconfig/ \
        -cn SHU \
        -ks /usr/share/elasticsearch/config/node-keystore.jks \
        -kspass Chupacabra \
        -ts /usr/share/elasticsearch/config/truststore.jks \
        -tspass Chupacabra \
        -nhnv
like image 499
nbrink Avatar asked Apr 05 '17 15:04

nbrink


1 Answers

We were able to get this working. We just had to add the script to the CMD command at the end of our Dockerfile so it ran after the ElasticSearch startup script.

It looks like you can only have one command per file so we had to look at the base Elastic image (ElasticSearch Docker GitHub) and add to it.

CMD ["/bin/bash", "bin/es-docker", "search-guard/run-sgadmin.sh"]

like image 109
nbrink Avatar answered Sep 28 '22 06:09

nbrink