amihaiemil / amihaiemil/docker-java-api

How to run a Exec

Offen
#386 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
274
Forks
56
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

How to run the Exec instance after create it, I have dig throught the repo but cant find a way to make it work, here is my code below:

```Java
public String testDockerClient () {
try{
final Docker dockerClient = new UnixDocker(new File("/var/run/docker.sock"));
final Container started = dockerClient.containers().create("my-python-runner:latest");

JsonArray cmdArray = Json.createArrayBuilder()
.add("echo")
.add("helloword")
.build();

JsonObject execConfig = Json.createObjectBuilder()
.add("Cmd", cmdArray)
.add("AttachStdin", false)
.add("AttachStdout", true)
.add("AttachStderr", true)
.add("Tty", false)
.build();

started.start();

Exec output = started.exec(execConfig);
System.out.println("output: " + output.inspect());
Logs log = started.logs();
System.out.println("log: " + log.toString());
started.stop();
started.remove();

return "Success";

} catch (Exception e) {
return "Error: " + e.getMessage();
}
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.