如何捆绑弹性search模板与docker的形象?

我目前正在build立一个自定义的docker镜像用于集成testing。 我的要求是使用默认的ingesterpipe道和模板映射的自定义configuration来设置它。

Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch:5.6.2 ADD config /usr/share/elasticsearch/config/ USER root RUN chown -R elasticsearch:elasticsearch config RUN chmod +x config/setup.sh USER elasticsearch RUN elasticsearch-plugin remove x-pack EXPOSE 9200 EXPOSE 9300 

其中config是一个包含以下内容的目录:

 > elasticsearch.yml for the configuration > templates in the form of json files > setup.sh - script which executes curl to es in order to register pipelines to _ingester and template mappings 

安装脚本如下所示:

 #!/bin/bash # This script sets up the es5 docker instance with the correct pipelines and templates baseUrl='127.0.0.1:9200' contentType='Content-Type:application/json' # filebeat filebeatUrl=$baseUrl'/_ingest/pipeline/filebeat-pipeline?pretty' filebeatPayload='@pipeline/filebeat-pipeline.json' echo 'setting filebeat pipeline...' filebeatResult=$(curl -XPUT $filebeatUrl -H$contentType -d$filebeatPayload) echo -e "filebeat pipeline setup result: \n$filebeatResult" # template echo -e "\n\nsetting up templates..." sleep 1 cd template for f in *.json do templateName="${f%.*}" templateUrl=$baseUrl'/_template/'$templateName echo -e "\ncreating index template for $templateName..." templateResult=$(curl -XPUT $templateUrl -H$contentType -d@$f) echo -e "$templateName result: $templateResult" sleep 1 done echo -e "\n\n\nCompleted ES5 Setup, refer to logs for details" 

我如何构build和运行脚本,使脚本在弹性启动后运行?

我通常做的是包括一个像你一样的温暖的脚本,并在开始时添加以下几行。 在Docker中,我没有其他方法可以等待底层服务的启动

 # wait until ES is up until $(curl -o /dev/null -s --head --fail $baseUrl); do echo "Waiting for ES to start..." sleep 5 done 

如果模板映射不是经常演变,那么你可以尝试下面的解决scheme:

您可以使用以下步骤通过保存容器状态(创build新图像)在自定义图像中embedded模板:

  1. 根据你的dockerfile运行你的镜像(elasticsearch会被注意到)
  2. 使用docker exec命令来运行你的模板(curl命令或脚本)
  3. 使用docker commit保存容器状态并创build已经有模板的新图像

使用已经有模板映射的新创build的图像。您不需要将模板映射作为脚本的一部分,因为您的图像本身会拥有它。