Docker 1.9允许将参数传递给dockerfile.请参阅链接:https://docs.docker.com/engine/reference/builder/#arg
我怎样才能在ENTRYPOINT指令中传递相同的句子?
我的dockerfile有
ARG $ Version = 3.1
ENTRYPOINT /tmp/folder-$Version/sample.sh start
使用上面的dockerfile创建容器时出错.请建议在ENTRYPOINT指令中指定参数的正确方法是什么?
像布雷克米切尔最高审计机关,不能使用ARG
在ENTRYPOINT
.但是,您可以使用它ARG
作为值ENV
,这样您就可以使用它ENTRYPOINT
:
Dockerfile
ARG my_arg ENV my_env_var=$my_arg ENTRYPOINT echo $my_env_var
简短的回答:你需要使用 ENV
双方ARG
并ENV
没有在扩大ENTRYPOINT
或CMD
.(https://docs.docker.com/engine/reference/builder/#environment-replacement)但是,因为ENV
s是作为环境的一部分传入的,所以它们在运行时可用,因此shell可以扩展它们.(这意味着你不能使用ENTRYPOINT
或的数组形式CMD
.)
这是一个例子:
$ cat arg/Dockerfile FROM debian:jessie ARG FOO=bar ENTRYPOINT echo ${FOO:-foo} $ sudo docker build arg Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian:jessie ---> f50f9524513f Step 2 : ARG FOO=bar ---> Using cache ---> 2cfdcb514b62 Step 3 : ENTRYPOINT echo ${FOO:-foo} ---> Running in 21fb9b42c10d ---> 75e5018bad83 Removing intermediate container 21fb9b42c10d Successfully built 75e5018bad83 $ sudo docker run 75e5018bad83 foo $ sudo docker run -e FOO=bas 75e5018bad83 bas $ sudo docker build --build-arg FOO=bas arg Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian:jessie ---> f50f9524513f Step 2 : ARG FOO=bar ---> Using cache ---> 2cfdcb514b62 Step 3 : ENTRYPOINT echo ${FOO:-foo} ---> Using cache ---> 75e5018bad83 Successfully built 75e5018bad83 $ sudo docker run 75e5018bad83 foo $ cat env/Dockerfile FROM debian:jessie ARG FOO=bar ENV FOO=${FOO} ENTRYPOINT echo ${FOO:-foo} $ sudo docker build env Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian:jessie ---> f50f9524513f Step 2 : ARG FOO=bar ---> Using cache ---> 2cfdcb514b62 Step 3 : ENV FOO ${FOO} ---> Running in f157a07c1b3e ---> a5e8c5b65a17 Removing intermediate container f157a07c1b3e Step 4 : ENTRYPOINT echo ${FOO:-foo} ---> Running in 66e9800ef403 ---> 249fe326e9ce Removing intermediate container 66e9800ef403 Successfully built 249fe326e9ce $ sudo docker run 249fe326e9ce bar $ sudo docker run -e FOO=bas 249fe326e9ce bas $ sudo docker build --build-arg FOO=bas env Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian:jessie ---> f50f9524513f Step 2 : ARG FOO=bar ---> Using cache ---> 2cfdcb514b62 Step 3 : ENV FOO ${FOO} ---> Running in 6baf31684b9f ---> 8f77ad154798 Removing intermediate container 6baf31684b9f Step 4 : ENTRYPOINT echo ${FOO:-foo} ---> Running in 892ac47cabed ---> fa97da85bf8a Removing intermediate container 892ac47cabed Successfully built fa97da85bf8a $ sudo docker run fa97da85bf8a bas $