docker - 如何将elasticsearch模板与docker镜像捆绑在一起?

标签 docker elasticsearch

我目前正在构建一个用于集成测试的自定义 Docker 镜像。我的要求是使用带有默认摄取管道和模板映射的自定义配置来设置它。

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"

如何构建和运行图像,以便在弹性启动并运行后执行脚本?

最佳答案

我通常做的是包含一个像你这样的温暖脚本,并在开头添加以下几行。据我所知,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

关于docker - 如何将elasticsearch模板与docker镜像捆绑在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46560565/

相关文章:

bash - 2013: “Lost connection to MySQL server at '握手:读取初始通信数据包',尝试连接时系统错误:115”

ruby-on-rails - docker postgres 图像 - 初始化失败,数据库服务不健康

linux - Linux Mint 19.2 上的 Docker 安装不起作用

elasticsearch - 用连字符_analyze端点分析文本

docker - Kibana docker 与外部 Elasticsearch 组合

elasticsearch - Elasticsearch:使用两个节点设置集群

java - 使用 Windows 操作系统、Java、Selenium、Jenkins 从 Dockerfile 构建 docker 容器

linux - 配置ELK堆栈

elasticsearch - 使用种子 URL 更新主机字段名称

docker - 我可以在 Microsoft IoT Edge 中运行任何 docker 容器吗?