title: Collecting output from Docker in java application
body: <p>I'm executing some code on docker in my java application using ProcessBuilder to run the code, however i'm having trouble retrieving the output from it. BufferedReader is not reading anything from the InputStream returned from the container. Is there a specific way to retrieve output from Docker??
  I've never had trouble getting output from bash executions before, so I'm thinking maybe docker does things differently somehow. Any ideas would be appreciated</p>
  
  <p>Here's a snippet of the code:</p>
  
  <pre><code>    Process dockerCommand;
      ProcessBuilder builder = new ProcessBuilder("bash","-c","sudo docker images");
      builder.redirectErrorStream(true);
      builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
      builder.redirectError(ProcessBuilder.Redirect.INHERIT);
      dockerCommand = builder.start();       
  
      dockerCommand.waitFor();
  
      List&lt;String&gt; result = new ArrayList&lt;&gt;();
      try (BufferedReader reader = new BufferedReader(new InputStreamReader(dockerCommand.getInputStream()))
      {
          String line = reader.readLine();
          while (line != null) {
              result.add(line);
              line = reader.readLine();
          }
      } 
      catch (IOException exc) 
      {}
  </code></pre>