如何将参数与docker-compose一起传递? [英] How do I pass an argument along with docker-compose up?
问题描述
我有一个 docker-compose.yml
文件,并且在终端中我正在 typing docker-compose up [something]
,但我也想将一个参数传递给 docker-compose.yml
.这可能吗?我已经了解了插值变量,并尝试使用 $ {testval}
在 .yml
文件中指定一个变量,然后使用 docker-compose up [something] var="test"
,但出现以下错误:
I have a docker-compose.yml
file and in the terminal I am typing docker-compose up [something]
but I would also like to pass an argument to docker-compose.yml
. Is this possible? I've read about interpolation variables and tried to specify a variable in the .yml
file using ${testval}
and then docker-compose up [something] var="test"
but I receive the following error:
警告:未设置testval变量.默认为空字符串.
错误:无此类服务:testval = test
推荐答案
基于示例仓库,您可以将变量传递给docker-compose up.
Based on dnephin answer, I created this sample repo that you can pass an variable to docker-compose up.
用法很简单:
-
TEST = docker-compose up
创建并启动app
和db
容器.然后,该api应该在端口3030上的docker守护程序上运行. -
TEST = DO docker-compose up
来创建和启动app
和db
容器.api应该在package.json
文件中执行npm run test
.
TEST= docker-compose up
to create and start bothapp
anddb
container. The api should then be running on your docker daemon on port 3030.TEST=DO docker-compose up
to create and start bothapp
anddb
container. The api should execute thenpm run test
inside thepackage.json
file.
-
$ env:TEST ="; docker-compose up
创建并启动app
和db
容器.然后,该api应该在端口3030上的docker守护程序上运行. -
$ env:TEST ="do"; docker-compose up
创建并启动app
和db
容器.api应该在package.json
文件中执行npm run test
.
$env:TEST="";docker-compose up
to create and start bothapp
anddb
container. The api should then be running on your docker daemon on port 3030.$env:TEST="do";docker-compose up
to create and start bothapp
anddb
container. The api should execute thenpm run test
inside thepackage.json
file.
这篇关于如何将参数与docker-compose一起传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!