如何将Elasticsearch模板与Docker映像捆绑在一起? [英] How to bundle elasticsearch templates with docker image?

查看:53
本文介绍了如何将Elasticsearch模板与Docker映像捆绑在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个自定义docker映像以用于集成测试.我的要求是使用默认的ingester管道和模板映射通过自定义配置进行设置.

Im currently building a custom docker image to be used for integration test. My requirement is to set it up with custom configuration with default ingester pipeline and template mappings.

Dockerfile:

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 是包含以下内容的目录:

where config is a directory which contains:

> 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"

在Elastic正常运行后,如何以执行脚本的方式构建和运行映像?

How do i build and run the image in such a way that the script gets executed AFTER elastic is up and running?

推荐答案

我通常要做的是包括一个像您这样的较暖的脚本,并在开始时添加以下几行.我在Docker中没有其他方法可以等待基础服务启动

What I usually do is to include a warmer script like yours and at the beginning I add the following lines. There's no other way that I know of in Docker to wait for the underlying service to launch

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

这篇关于如何将Elasticsearch模板与Docker映像捆绑在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆