Tarun Maganti
Tarun Maganti

Reputation: 3086

How to run docker commands in windows using a Java program?

Ref: https://rominirani.com/docker-on-windows-mounting-host-directories-d96f3f056a2c

I want to manipulate my data by using docker image of gdal. The problem is I have to create a GUI wrapper in Java using Swing. How can run the docker command from Java ProcessBuilder? That is run the powershell commands from Java.

Upvotes: 0

Views: 439

Answers (2)

SoT
SoT

Reputation: 1215

ProcessBuilder pb = new ProcessBuilder("ipconfig", "/all");
BufferedReader br = new BufferedReader(new InputStreamReader(pb.start().getInputStream()));
String str = "";
while ((str = br.readLine()) != null) {
    System.out.println(str);
}

Replace "ipconfig", "/all" by your command (ex: "docker", "ps", "--all")

Upvotes: 2

madhead
madhead

Reputation: 33422

There are a plenty of Java wrappers around Docker API, like docker-java or docker-java-api. Pick one and you're good to go.

Upvotes: 3

Related Questions