当ENTRYPOINT存在时,Docker运行命令忽略Dockerfile CMD的一部分

时间:2016-05-13 09:55:48

标签: docker dockerfile

当我运行我的docker容器时,它似乎只是尊重CMD数组的第一个元素(python可执行文件)并忽略尾随参数。

Dockerfile:

$ docker run --rm -it --volume $(pwd)/..:/mycode --volume mycontainer-virtualenv:/virtualenv mycontainer

运行命令:

Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

输出:

--detach

如果我运行-it而非$ docker run --rm -it --volume $(pwd)/..:/mycode --volume mycontainer-virtualenv:/virtualenv mycontainer /virtualenv/bin/python /mycode/myscript.py --param1 Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ,则会发生同样的情况。

如果我使用CMD作为重写的docker run参数运行,也会发生同样的事情:

$ docker run --rm -it --volume $(pwd)/..:/mycode --volume mycontainer-virtualenv:/virtualenv mycontainer bash
root@d6a990e81c22:/# /virtualenv/bin/python /mycode/myscript.py --param1
Hello world!

如果我使用bash运行容器并从bash提示符运行CMD,它可以正常工作:

if self.isKindOfClass(RightViewController.classForCoder()) {
    let controller: RightViewController = self as! RightViewController
}

1 个答案:

答案 0 :(得分:3)

你可能想要

$pdf->Image($profile,10,'',30);

而不是

CMD ["/virtualenv/bin/python /mycode/myscript.py --param1"]

当Dockerfile中存在CMD ["/virtualenv/bin/python", "/mycode/myscript.py", "--param1"] CMD时,CMD将作为ENTRYPOINT的默认参数。所以你基本上做了

ENTRYPOINT

何时需要

bash -c "/virtualenv/bin/python" "/mycode/myscript.py" "--param1"

https://docs.docker.com/engine/reference/builder/#cmd https://docs.docker.com/engine/reference/builder/#entrypoint https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact

相关问题