将环境变量添加到elasticsearch dockerfile

时间:2019-08-09 11:38:29

标签: docker elasticsearch dockerfile

我有一个工作的dockerfile,按如下所示设置elasticsearch:

FROM elasticsearch:6.5.4
WORKDIR /app
ADD . /app
ADD analysis /usr/share/elasticsearch/config/analysis
COPY test.sh .
EXPOSE 9200
EXPOSE 9300

我当前的文件目录如下:

C:.
|   Dockerfile
|   test.sh
|
+---analysis
|       wn_s.pl
|
\---poppler
    +---bin
    |       AUTHORS
    |       BINARIES
    |       COPYING
    |       COPYING3
    |       freetype6.dll
    |       jpeg62.dll

我想将poppler内的bin文件夹作为环境变量PATH进行Elasticsearch。为此,我在dockerfile后面附加了

FROM elasticsearch:6.5.4
WORKDIR /app
ADD . /app
ADD analysis /usr/share/elasticsearch/config/analysis
COPY test.sh .
EXPOSE 9200
EXPOSE 9300
ENV PATH=/app/es/poppler/bin

结果是创建了映像,但是当使用该映像创建容器时,其退出会在docker日志中以以下错误开始:

/usr/local/bin/docker-entrypoint.sh: line 62: env: command not found
/usr/local/bin/docker-entrypoint.sh: line 93: id: command not found
/usr/local/bin/docker-entrypoint.sh: line 8: id: command not found
/usr/share/elasticsearch/bin/elasticsearch: line 17: dirname: command not found
/usr/share/elasticsearch/bin/elasticsearch: line 17: /elasticsearch-env: No such file or directory
/usr/share/elasticsearch/bin/elasticsearch: line 20: : command not found
/usr/share/elasticsearch/bin/elasticsearch: line 25: grep: command not found
/usr/share/elasticsearch/bin/elasticsearch: line 27: exec: : not found

在以前的项目中,以类似的方式添加环境变量已经取得了成功,但是,尽管在stackoverflow上进行了搜索,但我仍无法弄清问题出在哪里。

2 个答案:

答案 0 :(得分:1)

您只是改写了默认PATH,因此容器找不到任何可执行文件,这就是您看到这些错误的原因。

修复: ENV PATH="/app/es/poppler/bin:${PATH}"

这将允许您保留现有路径并添加自定义。

答案 1 :(得分:1)

如注释中所建议,您替换了PATH环境变量的值,而不是将其添加到其中。

替换

ENV PATH=/app/es/poppler/bin

使用

ENV PATH='${PATH}:/app/es/poppler/bin'