gpt4 book ai didi

docker - env_file在docker-compose中被忽略并导致 “The … variable is not set”警告

转载 作者:行者123 更新时间:2023-12-02 20:47:52 33 4
gpt4 key购买 nike

我只想使用从docker-compose文件中的文件加载的环境变量。但是在运行容器之后,我只有

WARNING: The TESTVAR variable is not set. Defaulting to a blank string.



只找到 this topic,但是我正在使用更高版本的docker(如docker-compose: 1.14.0,docker: 17.05.0-ce)。并且我将编码更改为 ISO 8859-1,因为我发现了一个github问题,其中检测到了奇怪的编码行为。两者都不起作用。

我的docker-compose文件
version: '2'
services:
mysql:
container_name: test_${TESTVAR}
build: mysql
mem_limit: 1G
env_file:
- credentials.env

certificate.env仅包含 TESTVAR=test123。首先,我运行 docker-compose up mysql,我还尝试直接在撰写文件中指定环境变量,如下所示:
environment:
- TESTVAR=1234

也不行。

最佳答案

如果要在docker-compose.yml中使用变量,则可以使用.env文件docker docs

$ cat .env
TAG=v1.5
TESTVAR=123

$ cat docker-compose.yml
version: '3'
services:
web:
image: "webapp:${TAG}"
environment: ["TESTVAR=${TESTVAR}"]

关于docker - env_file在docker-compose中被忽略并导致 “The … variable is not set”警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607848/

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