Hi!
I'm trying to execute an interactive container from a Java Application (I'm building an online free Java compiler). But for some reason the termination signal is not received and the Java application thinks that the program continues running (Docker version 1.5.0, build a8a31ef)
The attached code hangs on the process.waitFor(). But if I remove the -i flag the program runs ok
Maybe this issue is related to this other fixed before -> #6509
I need the program to run with the -i flag due that I want to execute interactive Java programs inside the docker container. Also I tried with the -t flag but Java does not provide a TTY so it fails to execute.
One thing that I cannot figure out is why the docker command works from the command line but no from the java application, maybe the difference is that I have a TTY when I execute the command from the command line
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class Test {
public static void main(String[] args) throws Exception {
Process process = Runtime.getRuntime().exec("sudo docker run -i ubuntu ls");
int returnCode = process.waitFor();
System.out.println("returnCode: " + returnCode);
System.out.println("output: " + output(process.getInputStream()));
}
private static String output(InputStream inputStream) throws IOException {
StringBuilder sb = new StringBuilder();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while ((line = br.readLine()) != null) {
sb.append(line + System.getProperty("line.separator"));
}
} finally {
br.close();
}
return sb.toString();
}
}
Hi!
I'm trying to execute an interactive container from a Java Application (I'm building an online free Java compiler). But for some reason the termination signal is not received and the Java application thinks that the program continues running (Docker version 1.5.0, build a8a31ef)
The attached code hangs on the process.waitFor(). But if I remove the -i flag the program runs ok
Maybe this issue is related to this other fixed before -> #6509
I need the program to run with the -i flag due that I want to execute interactive Java programs inside the docker container. Also I tried with the -t flag but Java does not provide a TTY so it fails to execute.
One thing that I cannot figure out is why the docker command works from the command line but no from the java application, maybe the difference is that I have a TTY when I execute the command from the command line
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Test { public static void main(String[] args) throws Exception { Process process = Runtime.getRuntime().exec("sudo docker run -i ubuntu ls"); int returnCode = process.waitFor(); System.out.println("returnCode: " + returnCode); System.out.println("output: " + output(process.getInputStream())); } private static String output(InputStream inputStream) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader br = null; try { br = new BufferedReader(new InputStreamReader(inputStream)); String line = null; while ((line = br.readLine()) != null) { sb.append(line + System.getProperty("line.separator")); } } finally { br.close(); } return sb.toString(); } }