且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ENTRYPOINT数组中使用Docker环境变量?

更新时间:2023-08-21 10:47:04

您使用的是ENTRYPOINT的 exec表单。与 shell表单不同, exec表单不调用命令shell。这意味着不会发生正常的shell处理。例如,$ code> ENTRYPOINT [echo,$ HOME] 不会在$ HOME上执行变量替换。如果你想要shell处理,那么可以使用 shell窗体或直接执行shell,例如: ENTRYPOINT [sh,-c,echo,$ HOME]

当使用exec窗体并直接执行一个shell时,就像shell窗体一样,它是正在进行环境变量扩展的shell,不是码头(从 Dockerfile参考

You're using the exec form of ENTRYPOINT. Unlike the shell form, the exec form does not invoke a command shell. This means that normal shell processing does not happen. For example, ENTRYPOINT [ "echo", "$HOME" ] will not do variable substitution on $HOME. If you want shell processing then either use the shell form or execute a shell directly, for example: ENTRYPOINT [ "sh", "-c", "echo", "$HOME" ].
When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker.(from Dockerfile reference)

在你的情况下,我将使用 shell窗体

In your case, I would use shell form

ENTRYPOINT ./greeting --message "Hello, $ADDRESSEE\!"