title: How to send emails on failures of a dockerized application?
body: <p>I had a <strong>python</strong> application, which, with the use of <strong>shell</strong> tricks, was able to send me <strong>emails</strong> when new error messages appeared in the log during an execution session, scheduled with <strong>cron</strong>. </p>
  
  <p>Now I am packing it in <strong>docker</strong> and was able to reproduce most of its functionality with <strong>docker-compose</strong>. </p>
  
  <p>But when it comes to emails on failures, I am not sure of what is the best way to implement it. </p>
  
  <p>What are your suggestions? Are there any best practices?</p>
  
  <p>Update:</p>
  
  <p>The app runs couple of times a day. Previously, all prints to stderr was duplicated to stdout to preserve chronological order in the main log file. Then, the wrapper script would accumulate all stderr from a single session in another, temporary file. And if that file was not empty after the session, its content was send in a single email from me to myself through SMTP with proper authentication. I was happy to receive and able to handle them for the last few months. </p>
  
  <p>Right now I see three possible solutions: </p>
  
  <ol>
  <li><p>Duplicating everything worth sending to a temporary file right in the app, this way docker logs would persist. Then sending it after the session from the entrypoint, provided, there is a way to setup in container all the requirements. </p></li>
  <li><p>Grepping docker log from the outside. But that's somewhat missing the point of docker.</p></li>
  <li><p>Relaying reports via local net to another container, with something like <a href="https://hub.docker.com/r/juanluisbaptiste/postfix/" rel="nofollow noreferrer">https://hub.docker.com/r/juanluisbaptiste/postfix/</a> which then will send it in a email </p></li>
  </ol>