我如何将参数与docker-compose一起传递 [英] How do i pass an argument along with docker-compose up
问题描述
我有一个 docker-compose.yml
文件,在终端中,我键入docker-compose up [某物]
,但我也想将参数传递给 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
推荐答案
基于 dnephin答案,我创建了这个样本仓库,您可以将变量传递给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应该在您的docker守护程序上的端口3030上运行。 -
TEST = DO docker-compose up
来创建和启动两者app
和db
容器。 api应该在package.json
文件中执行npm运行测试
。
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运行测试
。
$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屋!