title: How to detect if docker run succeeded programmatically?
body: <p>I'm writing a very simple bash script to quickly check that my container still builds and starts correctly and that the app inside responds to requests.</p>
  
  <p>Sometimes <code>docker run</code> fails, e.g. because the port I'm trying to bind the container to is already allocated. But when this happens <code>docker run</code>'s exit code is still 0 so I can't use the exit code. How can I check programmatically that the container got started correctly?</p>
  
  <p>The solutions I'm considering are:</p>
  
  <ul>
  <li>parse the output for errors</li>
  <li><code>docker ps</code> to see if the container is running</li>
  </ul>
  
  <p>but these both seem a little overkill and ugly. Am I missing a better way to check whether <code>docker run</code> succeeded?</p>