我如何将参数与docker-compose一起传递 [英] How do i pass an argument along with docker-compose up

查看:106
本文介绍了我如何将参数与docker-compose一起传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 both app and db container. The api should then be running on your docker daemon on port 3030.
  • TEST=DO docker-compose up to create and start both app and db container. The api should execute the npm run test inside the package.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 both app and db container. The api should then be running on your docker daemon on port 3030.
  • $env:TEST="do";docker-compose up to create and start both app and db container. The api should execute the npm run test inside the package.json file.

这篇关于我如何将参数与docker-compose一起传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆