Docker 问题,入口点 file.sh 无法识别 sun-exec 命令
Docker Problem, entrypoint file.sh doesnt recognize the su-exec command
我正在尝试构建一个具有弹性搜索 运行 的 docker 图像,并从该图像创建一个容器。
下面是我的 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"]
我要在 运行 以下命令时从 docker 文件成功构建映像:
docker build -t elasticsearch .
当我尝试使用以下命令创建容器时,我遇到了一些问题:
docker run -d --network host elasticsearch
容器已创建但直接终止。
以下是运行容器docker日志时的内容:
/elastic-entrypoint.sh: exec: line 20: su-exec: not found
下面是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 [ "" = '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 "$@"
好像set -- su-exec elasticsearch tini -- "$@"
没用
对于解决此问题的任何帮助或指导,我将不胜感激。
此致,
兰多.
更新...................................... ...............
我修改了文件如下:
#set -- su-exec elasticsearch tini -- "$@"
set -- su -c elasticsearch tini -- "$@"
显示错误:
su: unknown user tini
无法识别用户。
更新 2................................................ .....................
我通过添加安装 su-exe
的命令修改了 docker 文件,如下所示:
# Install required packages
RUN apk add --no-cache bash su-exec
容器退出并出现以下错误:
su-exec: tini: No such file or directory
尝试使用set -- su -c elasticsearch tini -- "$@"
此外,您不需要在 Dockerfile 中定义 CMD ["elasticsearch"]
。只需放入 elastic-entrypoint.sh 文件即可。
错误的原因是adoptopenjdk/openjdk8:alpine
没有包含su-exec包。我修改了 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
...
添加 su-exec
包解决了我的问题。
我正在尝试构建一个具有弹性搜索 运行 的 docker 图像,并从该图像创建一个容器。
下面是我的 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"]
我要在 运行 以下命令时从 docker 文件成功构建映像:
docker build -t elasticsearch .
当我尝试使用以下命令创建容器时,我遇到了一些问题:
docker run -d --network host elasticsearch
容器已创建但直接终止。
以下是运行容器docker日志时的内容:
/elastic-entrypoint.sh: exec: line 20: su-exec: not found
下面是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 [ "" = '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 "$@"
好像set -- su-exec elasticsearch tini -- "$@"
没用
对于解决此问题的任何帮助或指导,我将不胜感激。
此致, 兰多.
更新...................................... ...............
我修改了文件如下:
#set -- su-exec elasticsearch tini -- "$@"
set -- su -c elasticsearch tini -- "$@"
显示错误:
su: unknown user tini
无法识别用户。
更新 2................................................ .....................
我通过添加安装 su-exe
的命令修改了 docker 文件,如下所示:
# Install required packages
RUN apk add --no-cache bash su-exec
容器退出并出现以下错误:
su-exec: tini: No such file or directory
尝试使用set -- su -c elasticsearch tini -- "$@"
此外,您不需要在 Dockerfile 中定义 CMD ["elasticsearch"]
。只需放入 elastic-entrypoint.sh 文件即可。
错误的原因是adoptopenjdk/openjdk8:alpine
没有包含su-exec包。我修改了 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
...
添加 su-exec
包解决了我的问题。