如何将 ARG 值传递给 ENTRYPOINT? [英] How to pass ARG value to ENTRYPOINT?
问题描述
Docker 1.9 允许将参数传递给 dockerfile.见链接:https://docs.docker.com/engine/reference/builder/#arg
Docker 1.9 allows to pass arguments to a dockerfile. See link: https://docs.docker.com/engine/reference/builder/#arg
如何在 ENTRYPOINT 指令中传递相同的参数??
How can i pass the same arugments within ENTRYPOINT Instruction??
我的 dockerfile 有
My dockerfile has
ARG $Version=3.1
入口点/tmp/folder-$Version/sample.sh start
ARG $Version=3.1
ENTRYPOINT /tmp/folder-$Version/sample.sh start
我在使用上述 dockerfile 创建容器时遇到错误.请建议在 ENTRYPOINT 指令中指定参数的正确方法是什么??
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??
推荐答案
就像 Blake Mitchell 所说的那样,你不能在 ENTRYPOINT
中使用 ARG
.但是,您可以使用 ARG
作为 ENV
的值,这样您就可以将它与 ENTRYPOINT
一起使用:
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
然后运行:
docker build --build-arg "my_arg=foo" ...
这篇关于如何将 ARG 值传递给 ENTRYPOINT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!