[英]docker-compose can't use variables from .env
Docker Compose
can't use variables from .env
in docker-compose.yml
. Docker Compose
无法在docker-compose.yml
中使用来自.env
的变量。 .env
located in the same directory as docker-compose.yml
. .env
位于与docker-compose.yml
相同的目录中。
.env:环境:
port:3306
docker-compose.yml: docker-compose.yml:
ports:
- ${port}:${port}
The documentation shows exactly the same example and says that it works该文档显示了完全相同的示例并说它有效
web:
image: "webapp:${TAG}"
I have error while executing docker-compose up
执行docker-compose up
出现错误
WARNING: The port variable is not set. Defaulting to a blank string.
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.mariadb.ports is invalid: Invalid port ":", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]
How to fix it?如何解决?
It seems your.env format is wrong.看来 your.env 格式不对。 Try:尝试:
PORT = 3306
From https://docs.docker.com/compose/env-file/ :来自https://docs.docker.com/compose/env-file/ :
Syntax rules语法规则
These syntax rules apply to the.env file:这些语法规则适用于 .env 文件:
- Compose expects each line in an env file to be in VAR=VAL format. Compose 期望 env文件中的每一行都采用 VAR=VAL 格式。
- Lines beginning with # are processed as comments and ignored.以 # 开头的行将作为注释处理并被忽略。
- Blank lines are ignored.空行被忽略。
- There is no special handling of quotation marks.没有引号的特殊处理。 This means that they are part of the VAL.这意味着它们是 VAL 的一部分。
in .env
, use =
instead of :
在.env
中,使用=
而不是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.