命令 '/bin/sh -c 返回非零代码:127

The command '/bin/sh -c returned a non-zero code: 127

我是 docker 的新手,所以我可能做错了,但我正在尝试通过 Dockerfile 安装 Tomcat6,如下所示:

FROM rhel7:latest
RUN cd /tmp
RUN "wget", "http://www.us.apache.org/dist/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz"
RUN tar xzf apache-tomcat-6.0.44.tar.gz
RUN mv apache-tomcat-6.0.44 /usr/local/tomcat6
RUN cd /usr/local/tomcat6
Run ./bin/start.sh

它在第 3 行失败:

  RUN "wget", "http://www.us.apache.org/dist/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz"

当我 运行 构建 docker 时,我得到了这个:

我正在使用:

在此先感谢您的帮助。

图片出错的解决方法是在wget CMD RUN yum -y install wget

之前加上

这样写也是一样的结果,只是执行方式不同:

 RUN wget http://www.us.apache.org/dist/tomcat/tomcat-6/v6.0.44/bin/apache-tomcat-6.0.44.tar.gz

不要在 RUN 命令中使用引号和逗号。

shell 命令的退出代码 127 表示 "command not found"。因此,在您的情况下,当 Docker 运行 时似乎找不到引号内的 "wget" 。

在某些情况下,安装 wget 的命令(或任何缺少的命令行工具)必须首先是 Docker 文件中的 运行,因为一些基础 Docker 图像将没有wget。您可以在失败的命令之前添加一行,如下所示:

RUN yum install -y wget

别忘了你可以在同一行添加你需要的所有库和包

RUN cd /tmp \
&& apt-get update \
&& apt-get install -y curl apt-utils wget unzip\
&& rm -rf /var/lib/apt/lists/*