简体   繁体   English

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

[英]Docker run command ignoring part of Dockerfile CMD when ENTRYPOINT present

When I run my docker container, it appears to only be honouring the first element of the CMD array (python executable) and ignoring the trailing parameters. 当我运行我的docker容器时,它似乎只是尊重CMD数组的第一个元素(python可执行文件)并忽略尾随参数。

Dockerfile: Dockerfile:

FROM ubuntu:14.04

ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/virtualenv/bin/python", "/mycode/myscript.py", "--param1"]

Run command: 运行命令:

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

Output: 输出:

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.
>>>

Same happens if I run --detach instead of -it . 如果我跑同样的情况--detach而不是-it

Same also happens if I run with the CMD as an overriding docker run parameter: 如果我使用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, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

If I run the container with bash and run the CMD from the bash prompt, it works fine: 如果我用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!

You probably want 你可能想要

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

instead of 代替

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

When CMD and ENTRYPOINT are both present in Dockerfile, CMD works as default parameters to ENTRYPOINT. ENTRYPOINT中存在CMDENTRYPOINT ,CMD作为ENTRYPOINT的默认参数。 So you basically doing 所以你基本上做了

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

when you want 当你想要的时候

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 https://docs.docker.com/engine/reference/builder/#cmd https://docs.docker.com/engine/reference/builder/#entrypoint https://docs.docker.com/engine/reference/建设者/#明白,怎么-CMD-和入口点,相互作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM