I'm trying to send docker commands using Java Runtime.
Commands like docker cp works very nice with the below method as well as typing directly from the terminal.
First problem is that the
docker execcommand works only from the terminal, not with the Java Runtime. Other docker commands likedocker cpworks as expected. The only problem is that I can't run commands on the container, like echoing on the container's terminal.Also the 2nd problem is that the
System.out.println(...)method in the below method, doesn't actually print anything.
private static void runCommand() throws IOException, InterruptedException {
        Process proc = Runtime.getRuntime().exec(
                new String[]{"/bin/sh",
                        "-c",
                        "docker exec -u 0 -it <CONTAINER_NAME> echo",  "'abc'"});
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(proc.getInputStream()));
        String line = "";
        while ((line = reader.readLine()) != null) {
            System.out.print(line + "\n");
        }
        proc.waitFor();
}