DanH
DanH

Reputation: 5818

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.

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.

Same also happens if I run with the CMD as an overriding docker run parameter:

$ 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:

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

Upvotes: 4

Views: 4881

Answers (1)

Stas Makarov
Stas Makarov

Reputation: 726

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

Upvotes: 5

Related Questions