title: How to run python script (and receive output) from java/spring-boot project which is inside a docker container?
body: <p>I am trying to migrate services on my Ubuntu 16.04 server to docker 18.09.2 (so that I can leverage kubernetes).  My problem is getting a Jar to work in Docker the way it works in my local machine and server. </p>
  
  <p>Namely, I am trying to run a python script inside of my Java Spring Boot Application, capture the output of the Python, and then display the text. This works fine on my local machine , but when I build it on the docker base image and run it, nothing happens (i.e. null value is returned from Buffered Reader) </p>
  
  <p>The base docker image is 'openkbs/jre-mvn-py3'. The 'HelloWorld.py' file is located in the SpringBoot project directory.</p>
  
  <p>Taking from openkbs's documentation (<a href="https://hub.docker.com/r/openkbs/jre-mvn-py3/" rel="nofollow noreferrer">https://hub.docker.com/r/openkbs/jre-mvn-py3/</a>), I have tried a few different command's in my processString, but nothing is working. Commands like:</p>
  
  <p>docker run -it --rm openkbs/jdk-mvn-py3 python3 -c 'print("Hello World")'</p>
  
  <p>docker run -i --rm openkbs/jdk-mvn-py3 python3 &lt; HelloWorld.py </p>
  
  <p>Here are my relevant configurations and lines of code:</p>
  
  <p>Dockerfile:</p>
  
  <pre><code>FROM openkbs/jdk-mvn-py3
  ADD target/dockerMaster.jar dockerMaster.jar
  EXPOSE 8080
  ENTRYPOINT ["java", "-jar", "dockerMaster.jar"]
  </code></pre>
  
  <p>Java:</p>
  
  <pre class="lang-java prettyprint-override"><code>    @RequestMapping("/pytest")
      public String pytest() {
          Runtime rt = Runtime.getRuntime();
          String processString = "python3 HelloWorld.py";
          System.out.println(processString);
  
          try {
              Process extractProcess = rt.exec(processString);
              BufferedReader input = new BufferedReader(new InputStreamReader(extractProcess.getInputStream()));
              String pyString = input.readLine();
              return new String("&lt;PYSTUFF&gt;SUCCESS " + pyString + "&lt;/PYSTUFF&gt;");
          } catch (IOException e) {
              e.printStackTrace();
              return new String("&lt;FAIL&gt;PYTHON DID NOT RUN&lt;/FAIL&gt;");
          } 
      }
  
  </code></pre>
  
  <p>Python:</p>
  
  <pre class="lang-py prettyprint-override"><code>print("Hello World")
  </code></pre>