作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只想使用从docker-compose文件中的文件加载的环境变量。但是在运行容器之后,我只有
WARNING: The TESTVAR variable is not set. Defaulting to a blank string.
1.14.0
,docker:
17.05.0-ce
)。并且我将编码更改为
ISO 8859-1
,因为我发现了一个github问题,其中检测到了奇怪的编码行为。两者都不起作用。
version: '2'
services:
mysql:
container_name: test_${TESTVAR}
build: mysql
mem_limit: 1G
env_file:
- credentials.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/
我是一名优秀的程序员,十分优秀!