Franz They
Franz They

Reputation: 1015

Control docker-compose in Java

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?

Upvotes: 8

Views: 7129

Answers (2)

Matt
Matt

Reputation: 74720

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.

Upvotes: 2

sayboras
sayboras

Reputation: 5165

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.

Upvotes: 5

Related Questions