最近写docker-compose file时需要处理众多的环境变量,这些变量特性不一处理方式各异,特地去官方文档研究了一下docker-compose对环境变量的处理。
官方介绍的优先级顺序:
- Compose file
- Shell environment variables
- Environment file
- Dockerfile
- Variable is not defined
根据实际测试得到:
compose文件中的environment项
compose文件中的env_file项
用于compose的.env文件
有趣而特别需要注意的地方在于:
用于compose的.env文件 > compose文件中的默认值 > compose文件中的env_file项