[英]docker-compose load .env from dynamic path
I have below structure我有以下结构
The project root .env
defines the path to either ./docker/dev/.env
or ./docker/prod/.env
as depicted below:项目根.env
定义了./docker/dev/.env
或./docker/prod/.env
的路径,如下所示:
environment=dev
dot_env_path=./docker/dev/.env
My docker-compose.yml contains the below service snippet:我的 docker-compose.yml 包含以下服务片段:
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
env_file: ${dot_env_path} <--notice this variable points to the actual .env
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- 3306:3306
expose:
- 3306
volumes:
- db-tmc:/var/lib/mysql
However, when I do docker-compose
build I receive below warnings;但是,当我进行docker-compose
构建时,我收到以下警告; it's not detecting the ${dot_env_path}
and loading it's content它没有检测到${dot_env_path}
并加载它的内容
Any idea, much appreciated?任何想法,非常感谢?
Dont use environment:
if you are using the env_file
option.不要使用environment:
如果您使用的是env_file
选项。 It overrides the variables already added to the environment from the env_file:
option它覆盖已经从env_file:
选项添加到环境中的变量
Use this instead.改用这个。
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
env_file: ${dot_env_path}
ports:
- 3306:3306
expose:
- 3306
volumes:
- db-tmc:/var/lib/mysql
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.