amihaiemil / amihaiemil/docker-java-api

How to run a Exec

Aperta
#386 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
274
Fork
56
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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();
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.