Docker 1.9 allows to pass arguments to a dockerfile. See link: https://docs.docker.com/engine/reference/builder/#arg
How can i pass the same arugments within ENTRYPOINT Instruction??
My dockerfile has
ARG $Version=3.1
ENTRYPOINT /tmp/folder-$Version/sample.sh start
I am getting an error while creating container with above dockerfile. Please suggest what is the correct way to specify the argument within ENTRYPOINT instruction??
Just add the full ab command at the end of the docker run command. It will override the whole CMD specified in the Dockerfile. So if you want to pass the URL argument to ENTRYPOINT, you need to pass the URL alone. The reason is we have the ab command as part of the ENTRYPOINT definition.
Running containers can't access values of ARG variables. This also applies to CMD and ENTRYPOINT instructions which just tell what the container should run by default.
ENV is for future running containers. ARG for building your Docker image. ¶ ENV is mainly meant to provide default values for your future environment variables.
Docker ENTRYPOINT Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even when the container runs with command line arguments stated. A Docker ENTRYPOINT instruction can be written in both shell and exec forms: Exec form: ENTRYPOINT [“executable”, “parameter1”, “parameter2”]
Like Blake Mitchell sais, you cannot use ARG
in ENTRYPOINT
. However you can use your ARG
as a value for ENV
, that way you can use it with ENTRYPOINT
:
Dockerfile
ARG my_arg ENV my_env_var=$my_arg ENTRYPOINT echo $my_env_var
and run:
docker build --build-arg "my_arg=foo" ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With