如何在 env_file 中进行变量替换?

2023-12-19

我正在使用 docker-compose,我希望我的 env 文件具有变量替换。我想在文件中定义一个变量,然后在其他变量中使用它:

APP_ENV=dev-foo
LOCALPATH=/tmp/builddir/${APP_ENV}
[email protected] /cdn-cgi/l/email-protection:some-org/${APP_ENV}

env_file 中支持的变量替换形式是什么???


现在变量替换docker compose 支持 https://docs.docker.com/compose/environment-variables/env-file/#parameter-expansion

语法类似于 shell 替换。

直接替代

${VAR} -> value of VAR

默认值

${VAR:-default} -> value of VAR if set and non-empty, otherwise default
${VAR-default} -> value of VAR if set, otherwise default

所需值

${VAR:?error} -> value of VAR if set and non-empty, otherwise exit with error
${VAR?error} -> value of VAR if set, otherwise exit with error

替代价值

${VAR:+replacement} -> replacement if VAR is set and non-empty, otherwise empty
${VAR+replacement} -> replacement if VAR is set, otherwise empty
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 env_file 中进行变量替换? 的相关文章

随机推荐