简体   繁体   English

Docker 问题,入口点 file.sh 无法识别 su-exec 命令

[英]Docker Problem, entrypoint file.sh doesnt recognize the su-exec command

I am trying to build a docker image that has elastic search running and creating a container from that image.我正在尝试构建一个 docker 映像,该映像运行弹性搜索并从该映像创建一个容器。

Below is the content of my Dockerfile:下面是我的Dockerfile的内容:

FROM adoptopenjdk/openjdk8:alpine

MAINTAINER rando

COPY  elasticsearch-2.1.1.tar.gz /tmp

RUN    cd /tmp  \
    && tar -xzf  elasticsearch-2.1.1.tar.gz  \ 
    && ls    \
    && mv elasticsearch-2.1.1   /usr/share/elasticsearch   \
    && ls /usr/share \
       && adduser -DH -s /sbin/nologin elasticsearch \
       && chown -R elasticsearch:elasticsearch /usr/share/elasticsearch \
       && echo "Creating Elasticsearch Paths..." \
       && for path in /usr/share/elasticsearch/data /usr/share/elasticsearch/logs /usr/share/elasticsearch/config /usr/share/elasticsearch/config/scripts /usr/share/elasticsearch/plugins ; do mkdir -p "$path"; done \
       && chown -R elasticsearch:elasticsearch /usr/share/elasticsearch \
       && ls /usr/share/elasticsearch 

COPY elasticsearch.yml  /usr/share/elasticsearch/config
COPY elastic-entrypoint.sh /
RUN chmod +x /elastic-entrypoint.sh 

ENV  ES_HOME=/usr/share/elasticsearch   
ENV  PATH=${ES_HOME}/bin:${PATH}

RUN echo "$PATH"

VOLUME ["/usr/share/elasticsearch/data"]

EXPOSE 9200 9300

ENTRYPOINT ["/elastic-entrypoint.sh"]

CMD ["elasticsearch"]

I am to build successfully the image from the docker file when running the command below:运行以下命令时,我将从 docker 文件成功构建映像:

docker build -t elasticsearch .

When I try to create the container with the command below, I am facing some issues:当我尝试使用以下命令创建容器时,我遇到了一些问题:

docker run -d --network host elasticsearch

The container is created but is terminates directly.容器已创建但直接终止。

Below is the content when running the docker logs for the container:以下是容器运行 docker 日志时的内容:

/elastic-entrypoint.sh: exec: line 20: su-exec: not found

Below is the content of elastic-entrypoint.sh file:下面是 elastic-entrypoint.sh 文件的内容:

#!/bin/sh

set -e

# Add elasticsearch as command if needed
if [ "${1:0:1}" = '-' ]; then
    set -- elasticsearch "$@"
fi

# Drop root privileges if we are running elasticsearch
# allow the container to be started with `--user`
if [ "$1" = 'elasticsearch' -a "$(id -u)" = '0' ]; then
    # Change the ownership of /usr/share/elasticsearch/data to elasticsearch
    chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data

    set -- su-exec elasticsearch tini -- "$@"
fi


exec "$@"

It seems that set -- su-exec elasticsearch tini -- "$@" is not working.似乎set -- su-exec elasticsearch tini -- "$@"不起作用。

I will appreciate any help or guidance to fix this issue.对于解决此问题的任何帮助或指导,我将不胜感激。

Regards, Rando.问候,兰多。

Update............................................................更新................................................. ............

I modified the file as below:我修改了文件如下:

    #set -- su-exec elasticsearch tini -- "$@"
    set -- su -c elasticsearch tini -- "$@"

It showed the error:它显示了错误:

su: unknown user tini

It is not recognizing the user.它无法识别用户。

Update 2...............................................................更新 2................................................. …………………………………………………………………………

I modified the dockerfile by adding the command for installation of su-exe like below:我修改了 dockerfile,添加了如下所示的su-exe安装命令:

# Install required packages
RUN apk add --no-cache bash su-exec

The container exited with the error below:容器退出并出现以下错误:

su-exec: tini: No such file or directory

Try to use set -- su -c elasticsearch tini -- "$@"尝试使用set -- su -c elasticsearch tini -- "$@"

Also you do not need to define CMD ["elasticsearch"] inside Dockerfile.此外,您不需要在 Dockerfile 中定义CMD ["elasticsearch"] Just put inside elastic-entrypoint.sh file.只需放入 elastic-entrypoint.sh 文件即可。

The cause of the error was that adoptopenjdk/openjdk8:alpine does not include the su-exec package.错误的原因是采用adoptopenjdk/openjdk8:alpine不包含su-exec package。 I modified the dockerfile as below:我修改了 dockerfile 如下:

FROM adoptopenjdk/openjdk8:alpine

MAINTAINER rando

# Install required packages
RUN apk add --no-cache bash su-exec
RUN apk add --update tini

COPY  elasticsearch-2.1.1.tar.gz /tmp

...

And adding su-exec package fixed the issue in my case.并添加su-exec package 解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM