Instead of calling Docker remote APIs, I need develop a program which just talks to Docker Linux Client (not Docker daemon). Here is my code
try {
String[] command = {"docker", "run", "-it", "tomcat:9", "bash"};
ProcessBuilder pb = new ProcessBuilder(command);
pb.inheritIO();
Process proc = pb.start();
InputStream is = proc.getInputStream();
OutputStream os = proc.getOutputStream();
BufferedReader reader
= new BufferedReader(new InputStreamReader(is));
BufferedWriter writer
= new BufferedWriter(new OutputStreamWriter(os));
writer.write("pwd");
writer.flush();
String line = "";
while ((line = reader.readLine()) != null) {
System.out.print(line + "\n");
}
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
I always get errors. If I use "-it", it will says "cannot enable tty mode on non tty input", if I use "-i", I will get a Stream Closed Exception.
Is there any way to solve this problem?