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