从环境变量循环获取 - name: "discovery.zen.minimum_master_nodes" value: "2" 带点类型的环境变量然后再放入数组 最后执行命令作为参数 另一种env的处理方法是启动容器后执行脚本 声明新变量赋值环境变量的值 sed 替换变量到 配置文件

 

$ cat bin/es-docker
#!/bin/bash
declare -a es_opts

while IFS='=' read -r envvar_key envvar_value
do
# Elasticsearch env vars need to have at least two dot separated lowercase words, e.g. `cluster.name`
if [[ "$envvar_key" =~ ^[a-z_]+\.[a-z_]+ ]]
then
if [[ ! -z $envvar_value ]]; then
es_opt="-E${envvar_key}=${envvar_value}"
es_opts+=("${es_opt}")
fi
fi
done < <(env)

export ES_JAVA_OPTS="-Des.cgroups.hierarchy.override=/ $ES_JAVA_OPTS"

exec bin/elasticsearch "${es_opts[@]}"

 

posted @ 2021-01-27 18:50  滴滴滴  阅读(226)  评论(0编辑  收藏  举报