FROM docker.elastic.co/elasticsearch/elasticsearch:5.5.2
USER root
WORKDIR /usr/share/elasticsearch/
ENV ES_HOSTNAME elasticsearch
ENV ES_PORT 9200
RUN chown elasticsearch:elasticsearch config/elasticsearch.yml
RUN chown -R elasticsearch:elasticsearch data
# install security plugin
RUN bin/elasticsearch-plugin install -b com.floragunn:search-guard-5:5.5.2-16
COPY ./safe-guard/install_demo_configuration.sh plugins/search-guard-5/tools/
COPY ./safe-guard/init-sgadmin.sh plugins/search-guard-5/tools/
RUN chmod +x plugins/search-guard-5/tools/init-sgadmin.sh
ADD ./run.sh .
RUN chmod +x run.sh
RUN chmod +x plugins/search-guard-5/tools/install_demo_configuration.sh
RUN ./plugins/search-guard-5/tools/install_demo_configuration.sh -y
RUN chmod +x sgadmin_demo.sh
RUN yum install tree -y
#RUN curl -k -u admin:admin https://localhost:9200/_searchguard/authinfo
RUN usermod -aG wheel elasticsearch
USER elasticsearch
EXPOSE 9200
#ENTRYPOINT ["nohup", "./run.sh", "&"]
ENTRYPOINT ["/usr/share/elasticsearch/run.sh"]
#CMD ["echo", "hello"]
一旦我添加CMD或Entrypoint - “容器退出代码为0”
#!/bin/bash
exec $@
如果我评论ENTRYPOINT或CMD - 一切都很棒。
我做错了什么???
答案 0 :(得分:1)
如果您查看官方5.6.9 elasticsearch Dockerfile,您会在底部看到以下内容:
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["elasticsearch"]
如果您不知道CMD
和ENTRYPOINT
之间的区别,请阅读this answer。
你正在做的是用其他东西覆盖这两条指令。你真正需要的是扩展CMD
。我通常在我的图像中做的是,创建一个sh
脚本并组合我需要的不同内容,然后指出CMD
的脚本。因此,您需要运行sgadmin_demo.sh
,但您需要先等待elasticsearch。创建start.sh
脚本:
#!/bin/bash
elasticsearch
sleep 15
sgadmin_demo.sh
现在,将您的脚本添加到您的图片并在CMD
上运行:
FROM: ...
...
COPY start.sh /tmp/start.sh
CMD ["/tmp/start.sh"]
现在应该在启动容器后执行。别忘了建立:)