首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将elasticsearch模板与docker图像捆绑?

如何将elasticsearch模板与docker图像捆绑?
EN

Stack Overflow用户
提问于 2017-10-04 08:42:38
回答 2查看 2.4K关注 0票数 1

我目前正在构建一个定制的码头形象,用于集成测试。我的要求是使用带有默认ingester管道和模板映射的自定义配置来设置它。

Dockerfile:

代码语言:javascript
复制
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是一个目录,其中包含:

代码语言:javascript
复制
> 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

安装脚本如下所示:

代码语言:javascript
复制
#!/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"

如何构建和运行映像,使脚本在弹性启动和运行后得到执行?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-10-04 09:15:50

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

代码语言:javascript
复制
# wait until ES is up
until $(curl -o /dev/null -s --head --fail $baseUrl); do
    echo "Waiting for ES to start..."
    sleep 5
done
票数 2
EN

Stack Overflow用户

发布于 2017-10-04 09:18:48

如果模板映射不经常进行,那么您可以尝试下面的解决方案:

通过使用以下步骤保存容器状态(创建新映像),可以将模板嵌入到自定义映像中:

  1. 按照您的dockerfile运行您的图像(elasticsearch会被盯着看)
  2. 使用docker命令运行模板(curl命令或脚本)
  3. 使用docker commit保存容器状态并创建已经有模板的新映像

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46560565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档