当我运行docker容器时,它似乎仅遵循CMD数组(python可执行文件)的第一个元素,而忽略了尾随参数.
Dockerfile:
FROM ubuntu:14.04
ENTRYPOINT ["/bin/bash","-c"]
CMD ["/virtualenv/bin/python","/mycode/myscript.py","--param1"]
运行命令:
$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,也会发生同样的情况.
如果将CMD作为覆盖的docker run参数运行,也会发生同样的情况:
$docker run --rm -it --volume $(pwd)/..:/mycode --volume mycontainer-virtualenv:/virtualenv mycontainer /virtualenv/bin/python /mycode/myscript.py --param1
Python 3.4.3 (default,"credits" or "license" for more information.
>>>
如果我使用bash运行容器并从bash提示符运行CMD,则可以正常工作:
$docker run --rm -it --volume $(pwd)/..:/mycode --volume mycontainer-virtualenv:/virtualenv mycontainer bash
root@d6a990e81c22:/# /virtualenv/bin/python /mycode/myscript.py --param1
Hello world!
最佳答案
你可能想要
原文链接:https://www.f2er.com/docker/532637.htmlCMD ["/virtualenv/bin/python /mycode/myscript.py --param1"]
代替
CMD ["/virtualenv/bin/python","--param1"]
当Dockerfile中同时存在CMD和ENTRYPOINT时,CMD用作ENTRYPOINT的默认参数.所以你基本上在做
bash -c "/virtualenv/bin/python" "/mycode/myscript.py" "--param1"
当你想要的时候
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