gpt4 book ai didi

linux - docker-compose 不能使用 .env 中的变量

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

Docker Compose不能使用 .env 中的变量在 docker-compose.yml . .envdocker-compose.yml 位于同一目录中.
.env:

port:3306
docker -compose.yml:
ports:
- ${port}:${port}
该文档显示了完全相同的示例并说它有效
web:
image: "webapp:${TAG}"
执行 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]
如何解决?

最佳答案

来自 https://docs.docker.com/compose/env-file/ :

Syntax rules

These syntax rules apply to the .env file:

  • Compose expects each line in an env file to be in VAR=VAL format.
  • 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.

.env , 使用 =而不是 :

关于linux - docker-compose 不能使用 .env 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64276748/

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