如何在docker内部以root身份运行elasticsearch?

时间:2019-03-15 12:36:30

标签: elasticsearch dockerfile

这是我的docker文件:

 FROM docker.elastic.co/elasticsearch/elasticsearch:6.6.0
    RUN cat /etc/group
    RUN chown -R root:root /usr/share/elasticsearch
    RUN chmod -R 777 /usr/share/elasticsearch
    RUN ls -ltr /usr/share/elasticsearch
    RUN chmod -R 777 /usr/share/elasticsearch
    ENV PATH=$PATH:/usr/share/elasticsearch/bin
    RUN yum -y update
    RUN yum -y install crontabs
    RUN echo  "root" > /etc/cron.allow
    RUN echo  "elasticsearch" >> /etc/cron.allow
    RUN echo "" >> /etc/cron.allow
    RUN chmod -R 777 /etc/cron.allow
    RUN chown -R elasticsearch /etc/cron.d
    RUN chmod -R 777 /etc/cron.d
    RUN chown -R elasticsearch /var/spool/cron
    RUN chmod -R 777 /var/spool/cron
    RUN chown -R elasticsearch /etc/crontab
    RUN chmod -R 777 /etc/crontab
    RUN chown -R  elasticsearch /etc/cron.d
    RUN chmod -R 777 /etc/cron.d
    RUN chown -R  elasticsearch /var/run
    RUN chmod -R 777 /var/run
    COPY ./purge.sh  /usr/share/elasticsearch
    RUN   touch /usr/share/elasticsearch/cron.log
    ADD ./cron /etc/cron.d/cron_test
    RUN chmod 0777 /etc/cron.d/cron_test
    RUN chown -R elasticsearch /etc/cron.d/cron_test
    USER elasticsearch
    RUN crontab /etc/cron.d/cron_test
    RUN chmod 777 /var/spool/cron/elasticsearch
    CMD elasticsearch
    USER root
    EXPOSE 9200 9300

我想以root用户身份运行elasticsearch,因为crontabjobs也以root用户身份运行。当我构建docker文件并使用以下命令运行它时,出现此问题:

212744798@GH71T8S2E MINGW64 ~/Documents/docke
$ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" es

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2019-03-15T12:22:34,596][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
        at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.6.0.jar:6.6.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.6.0.jar:6.6.0]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.6.0.jar:6.6.0]
        ... 6 more

如何用root用户运行elasticsearch?我需要更改任何权限吗?

0 个答案:

没有答案