用Java控制docker-compose [英] Control docker-compose in Java

查看:144
本文介绍了用Java控制docker-compose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了相当数量的docker-compose脚本,这些脚本产生了一些服务。我现在想在JVM中控制docker-compose。基本上,我希望能够执行 up down ,最好使用 -p < ; project name> 参数,这样我就可以同时生成多个实例。

I created a fairly amount of docker-compose scripts which spawn up several services. I now want to control docker-compose in the JVM. Basically, I want to be able to execute up and down, ideally with -p <project name> parameter, so I can spawn multiple instances at the same time.

在Java中这可能吗?

Is this possible in Java?

推荐答案

您可以采用两种可能的方法:

There might be two possible approaches that you can take:


  1. 使用常规命令执行程序(例如,借助ProcessBuilder并运行OS命令)运行docker-compose(上/下)

  2. 使用本地docker SDK ,目前官方支持golang和python,但可以在此处此处。现在,我将docker SDK与golang一起使用,并且看到我们可以以编程方式对docker进行几乎所有操作。

  1. Run docker-compose up/down using normal command executor (e.g. with the help of ProcessBuilder and run OS command)
  2. Using native docker SDK, currently golang and python are officially supported, but java docker client can be found here and here. For now, I am using docker SDK with golang, and see that we can programmatically do almost everything with docker.

这篇关于用Java控制docker-compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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