Docker Community Forums

Share and learn in the Docker community.

Problems running PHP script with multiple arguments


(Camerongo) #1

I have a container I’m using to run some CLI PHP scripts. My intention was to specify the entrypoint in the Dockerfile as the php executable and then pass the script name via CMD and then the arguments for the script at the docker run prompt. I’ve tried tons of combinations for the entrypoint and the cmd in the Dockerfile with no success. If I run php script.php --argument1=x --argument2=y from the shell it works fine. I am attempting to run docker run image --argument1=x --argument2=y. Each time I get back the php usage information indicating an improper structure in the php command. Here are some of the things I’ve tried in my Dockerfile:
ENTRYPOINT ["/usr/bin/php","-f"]
CMD [“registerwithmmc.php”]

ENTRYPOINT ["/usr/bin/php","-f",“registerwithmmc.php”]

CMD /usr/bin/php registerwithmmc.php

Has anyone seen this behavior before and does anyone have any suggestions?


(Ranjandas) #2

Hi,

This is the default behaviour. When ever you run a container from an image specifying some command at the end, Docker will replace CMD and will try to execute that. So in your case, If you give

ENTRYPOINT ["/usr/bin/php","-f"]
CMD ["registerwithmmc.php"]

and run the container as docker run image --argument1=x --argument2=y the result will become as shown below

ENTRYPOINT ["/usr/bin/php","-f"]
CMD ["--argument1=x", "--argument2=y"]

But your last pattern will work fine, as even if CMD gets replaced by your arguments , its actually passed on to the entrypoint which is actually executing the script.

ENTRYPOINT ["/usr/bin/php","-f","registerwithmmc.php"]
CMD /usr/bin/php registerwithmmc.php

So, in cases where you are planning to pass arguments to the container , you should execute the in-container task with Entrypoint.

Regards
Ranjan


(Camerongo) #3

Yeah - I hear what you are saying, but it isn’t working that way. Example:
My current docker file has only this:
ENTRYPOINT ["/usr/bin/php","-f",“registerwithmmc.php”]

I then run the container with this command:
docker run -ti docker.solohealth.net/muleregistermmc --agentname=muleesb --agentgroup=Prod-ESB --agentport=7777

But the output I get is this (as though none of the arguments were passed including the name of the script:
docker run -ti docker.solohealth.net/muleregistermmc --agentname=muleesb --agentgroup=Prod-ESB --agentport=7777


(Camerongo) #4

OK - I have it working now (and actually had an example of this working elsewhere). I’m not sure why the -f option was screwing things up, but that didn’t work outside of the container either. This works:
ENTRYPOINT ["/usr/bin/php", “registerwithmmc.php”]

And then execute the container like this:
docker run -ti docker.solohealth.net/muleregistermmc --agentname=muleesb --agentgroup=Prod-ESB --agentport=7777