How to pass ARG value to ENTRYPOINT?

meallhour picture meallhour · Dec 17, 2015 · Viewed 25.4k times · Source

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

Answer

Rotareti picture Rotareti · Dec 5, 2017

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