Docker CMD当ENTRYPOINT是一个shell脚本时很奇怪 [英] Docker CMD weirdness when ENTRYPOINT is a shell script

查看:1414
本文介绍了Docker CMD当ENTRYPOINT是一个shell脚本时很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的Dockerfile

Here's a simple Dockerfile

FROM centos:6.6
ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["echo", "foo"]

不幸的是它不起作用当您运行构建的结果容器时,没有任何回音。

如果您注释掉 ENTRYPOINT ,那么它可以工作。但是,如果将 ENTRYPOINT 设置为 / bin / sh -c ,则会再次失败

Unfortunately it doesn't work. Nothing is echo'd when you run the resulting container that's built.
If you comment out the ENTRYPOINT then it works. However, if you set the ENTRYPOINT to /bin/sh -c, then it fails again

FROM centos:6.6
ENTRYPOINT ["/bin/sh", "-c"]
CMD ["echo", "foo"]

我以为这是默认的 ENTRYPOINT 一个没有定义的容器,为什么没有这样的工作?

I thought that was the default ENTRYPOINT for an container that didn't have one defined, why didn't that work?

最后,这也有用

FROM centos:6.6
ENTRYPOINT ["/bin/bash", "-l", "-c"]
CMD ["echo foo"]

在提交问题之前,我想看看我是否在做某些事情错误?

我在我的容器内使用 rvm 需要一个登录shell正常工作。

Before I submit an issue, I wanted to see if I'm doing something obviously wrong?
I'm using rvm inside my container which sort of needs a login shell to work right.

推荐答案

请注意,官方centos 6图像的默认入口点/ cmd / a>是:

Note that the default entry point/cmd for an official centos 6 image is:


  • 无entrypoint

  • 只有 CMD [ / bin / bash]

  • no entrypoint
  • only CMD ["/bin/bash"]

如果您使用 / code>命令,您需要通过一个参数(这是完整的命令):echo foo

不是一系列参数( CMD [echo,foo] )。

If you are using the -c command, you need to pass one argument (which is the full command): "echo foo".
Not a series of arguments (CMD ["echo", "foo"]).

dockerfile CMD 部分所述:


如果您使用CMD的shell表单,那么< command> 将在 / bin / sh -c



FROM ubuntu
CMD echo "This is a test." | wc -




如果要运行 < command> 没有shell,那么您必须将该命令表达为JSON数组,并提供可执行文件的完整路径。

If you want to run your <command> without a shell then you must express the command as a JSON array and give the full path to the executable

由于 echo 是一个在bash和C shell中内置命令,这里的shell格式更为可取。

Since echo is a built-in command in the bash and C shells, the shell form here is preferable.

这篇关于Docker CMD当ENTRYPOINT是一个shell脚本时很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆