命令返回非零代码:127
我试图建立以下Dockerfile,但它一直未能在RUN ocp-indent --help
说ocp-indent: not found The command '/bin/sh -c ocp-indent --help' returned a non-zero code: 127
命令返回非零代码:127
FROM ocaml/opam
WORKDIR /workdir
RUN opam init --auto-setup
RUN opam install --yes ocp-indent
RUN ocp-indent --help
ENTRYPOINT ["ocp-indent"]
CMD ["--help"]
我撞坏成通过docker run -it <image id> bash -il
和前跑图像跑了ocp-indent --help
,它运行良好。不知道为什么它失败了,想法?
这是一个PATH相关的问题和配置文件。当您使用sh -c
或bash -c
时,配置文件未加载。但是当您使用bash -lc
时,它意味着加载配置文件并执行命令。现在您的配置文件可能有必要的路径设置来运行此命令。
编辑-1
因此,与原来的答案的问题是,它不能正常工作。当我们有
ENTRYPOINT ["/bin/bash", "-lc", "ocp-indent"]
CMD ["--help"]
它最终转化为/bin/bash -lc ocp-indent --help
,而它的工作,我们需要/bin/bash -lc "ocp-indent --help"
。这不能通过在入口点使用命令直接完成。所以,我们需要一个新的entrypoint.sh
文件
#!/bin/sh -l
ocp-indent "[email protected]"
确保chmod +x entrypoint.sh
主机。并更新Dockerfile以下
FROM ocaml/opam
WORKDIR /workdir
RUN opam init --auto-setup
RUN opam install --yes ocp-indent
SHELL ["/bin/sh", "-lc"]
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["--help"]
构建之后,并运行它的工作原理
$ docker run f76dda33092a
NAME
ocp-indent - Automatic indentation of OCaml source files
SYNOPSIS
原来的答复
您可以使用以下命令
docker run -it --entrypoint "/bin/sh" <image id> env
docker run -it --entrypoint "/bin/sh -l" <image id> env
docker run -it --entrypoint "/bin/bash" <image id> env
docker run -it --entrypoint "/bin/bash -l" <image id> env
方便地测试这两个之间的区别
现在,无论你有没有可以rect路径,或者只有在使用-l
标志时才会出现。在这种情况下,你可以改变你的泊坞窗映像的默认外壳下面
FROM ocaml/opam
WORKDIR /workdir
RUN opam init --auto-setup
RUN opam install --yes ocp-indent
SHELL ["/bin/bash", "-lc"]
RUN ocp-indent --help
ENTRYPOINT ["/bin/bash", "-lc", "ocp-indent"]
CMD ["--help"]
'SHELL'行看起来好像需要超越'RUN'行。谢谢。 – user1795832
我应该运行那些'docker run'命令的映像?将SHELL放在WORKDIR上面并构建它创建的映像,但由于此错误而不能在容器中运行:'来自守护程序的错误响应:oci运行时错误:container_linux.go:262:导致启动容器进程“exec:\” ocp-indent \“:在$ PATH中找不到可执行文件”' – user1795832
@ user1795832,我不好意思您应该只使用'ENTRYPOINT [“/ bin/bash”,“-lc”,“ocp-indent”]'。更新了回答中的代码 –
我不知道为什么它会如果'run'工程是必要的,但你试过指定为'ocp-完整路径indent'? – kichik
如何? '运行'? – user1795832
是的。它可能在'/ bin'或'/ usr/bin'中。 – kichik