Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass ARG value to ENTRYPOINT?

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

like image 852
meallhour Avatar asked Dec 16 '15 23:12

meallhour


People also ask

How do you pass arguments to ENTRYPOINT Docker?

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.

Can an ARG variable on Dockerfile be used by the running container?

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.

What is the difference between ARG and ENV in Dockerfile?

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.

Can we override Docker ENTRYPOINT?

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”]


1 Answers

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" ... 
like image 177
Rotareti Avatar answered Sep 24 '22 11:09

Rotareti