Control docker-compose in Java

女生的网名这么多〃 提交于 2020-03-01 04:38:07

问题


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.

Is this possible in Java?


回答1:


There might be two possible approaches that you can take:

  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.



回答2:


Docker Compose is a python utility that talks directly to the same Docker API as the all the other Docker clients. There's nothing fundamentally different about the commands it sends, but it does manage a lot of Docker container life cycle for you inside it's code.

Compose is based on the docker python module which is just another python Docker API client.

It would probably take a lot to reimplement the same in Java, here is the up method. Maybe try pulling that in with Jython if you really need to do it from the JVM or stick with executing the docker-compose commands from Java.



来源:https://stackoverflow.com/questions/47250271/control-docker-compose-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!