Environment variables precedence- docker compose
Environment variables precedence
https://docs.docker.com/compose/environment-variables/envvars-precedence/
The order of precedence (highest to lowest) is as follows:
- Set using
docker compose run -e
in the CLI- Substituted from your shell
- Set using the
environment
attribute in the Compose file- Use of the
--env-file
argument in the CLI- Use of the
env_file
attribute in the Compose file- Set using an
.env
file placed at base of your project directory- Set in a container image in the ENV directive. Having any
ARG
orENV
setting in aDockerfile
evaluates only if there is no Docker Compose entry forenvironment
,env_file
orrun --env
.
the host’s shell:
https://vsupalov.com/override-docker-compose-dot-env/
$ NAME="ENV" docker-compose up Recreating lab_ubuntu_1 ... done Attaching to lab_ubuntu_1 ubuntu_1 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ubuntu_1 | HOSTNAME=7ee3ce6e3965 ubuntu_1 | NAME=ENV ubuntu_1 | HOME=/root lab_ubuntu_1 exited with code 0
ARG和ENV的可用性
https://zhuanlan.zhihu.com/p/152957068
一旦引入ENV指令,ENV变量在构建过程中也可用。但与ARG不同,从最终映像开始的容器也可以访问它们。启动容器时,可以覆盖ENV值,更多信息请参见下文。
这是围绕从Dockerfile构建Docker映像并运行容器的过程中ARG和ENV可用性的简化概述。它们重叠,但是不能从容器内部使用ARG。
args override in compose file.
version: '3' services: somename: build: context: ./app dockerfile: Dockerfile args: some_variable_name: a_value
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。