title: Is there a way to get the error raised from a Python program outside Docker container and handle it?
body: <p>I have a container that runs a Python program and it can run in two ways, using <code>docker exec</code> in the localhost terminal or by making an API Rest request (that is outside the container) which executes the same command as it would be done by using the first method. What I am trying to do is whenever my Python program inside the container raises an error the API notice it.</p>
  
  <p>The error handling that is being done in the Python program is using logging.exception to print an error message and the traceback in terminal and in the API I am using the subprocess methos to make the <code>docker exec</code> (I know it would be better to use a Docker Compose and services but I can't now)</p>
  
  <p>The try/catch inside Docker container progam:</p>
  
  <pre class="lang-py prettyprint-override"><code>...
  try:
      ... something ...
  except IOError as e:
      self._log.exception("Error in my program\n{}".format(e))
  </code></pre>
  
  <p>The API function:</p>
  
  <pre class="lang-py prettyprint-override"><code>...
  try:
      CMD = "docker exec &lt;continer_id&gt; &lt;params&gt;"
      subprocess.check_output(CMD, shell=True)
      return{ 'response' : 'Done'}, 200
  except Exception as e:
      return{ 'response' : 'Error {}'.format(e)}, 500
  </code></pre>
  
  <p>I would like the API function to catch the exception raised inside Docker container. Or if it is no possible other way to do something like this.</p>