gpt4 book ai didi

docker - 无论如何,有一个DockerBuild文件使用环境变量文件吗?

转载 作者:行者123 更新时间:2023-12-02 21:24:21 25 4
gpt4 key购买 nike

我有一个Docker容器,该容器将具有大量(大约100个)自定义设置。与将默认值全部编码到DockerFile中相比,我希望具有更大的灵活性。我注意到docker run命令支持此选项:

--env-file value              Read in a file of environment variables (default [])

有没有办法让 docker build使用类似的文件驱动机制?还是完全有更好的方法?

最佳答案

Environment files are not supported for builds

This has been discussed at large and very likely won't be added. Introducing env in the build command creates host dependent builds.



The ARG command and --build-args are available during builds,但不支持您所需的文件。

正如 user2105103所建议的,您可以在构建步骤中复制env文件,然后在运行期间将其作为源。
COPY .env /.env
RUN set -uex; \
. /.env; \
echo $MY_ENV_VAR

关于docker - 无论如何,有一个DockerBuild文件使用环境变量文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41231029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com