在elasticsearch启动并在docker中运行后,如何运行searchguard设置脚本?

时间:2018-05-25 12:45:28

标签: docker elasticsearch dockerfile

我一直在努力让searchguard设置脚本init_sg.sh自动在elasticsearch之后运行。我不希望使用docker exec手动执行此操作。这是我尝试过的。

entrypoint.sh:

#! /bin/sh
elasticsearch
source init_sg.sh

Dockerfile:

FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.0

COPY config/ config/
COPY bin/ bin/

# Search Guard plugin
# https://github.com/floragunncom/search-guard/wiki
RUN elasticsearch-plugin install --batch com.floragunn:search-guard-6:6.1.0-20.1 \
    && chmod +x \
        plugins/search-guard-6/tools/hash.sh \
        plugins/search-guard-6/tools/sgadmin.sh \
    && chown -R elasticsearch config/sg/ \
    && chmod -R go= config/sg/


#  This custom entrypoint script is used instead of 
# the original's /usr/local/bin/docker-entrypoint.sh

ENTRYPOINT ["bash","-c","entrypoint.sh"]

但是,它会抛出cannot run elasticsearch as root error

org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

所以我想我不能直接在entrypoint.sh中运行elasticsearch,这很令人困惑,因为当Dockerfile是这样的时候没有问题:

FROM docker.elastic.co/elasticsearch/elasticsearch-oss:6.1.0

COPY config/ config/
COPY bin/ bin/
....
CMD ["elasticsearch"]

thread's接受的答案不起作用。没有" /run/entrypoint.sh"在容器中。

解决方案

最后,我设法完成了它。这是我自动运行Searchguard安装脚本的自定义入口点脚本:

source init_sg.sh

while [ $? -ne 0 ]; do
   sleep 10
   source init_sg.sh
done &

/bin/bash -c "source /usr/local/bin/docker-entrypoint.sh;"

如果您有任何其他解决方案,请随时回答。

0 个答案:

没有答案