title: Detect if docker ran successfully within the same script
body: <p>My <strong>script.sh</strong>:</p>
  
  <pre><code>#/bin/sh
  docker run --name foo 
  </code></pre>
  
  <p>(Just assume that the docker command works and the container name is foo. Can't make the actual command public.)</p>
  
  <p>I have a script that runs a docker container. I want to check that it ran successfully and <code>echo</code> the successful running status on the terminal. </p>
  
  <p>How can I accomplish this using the <code>container name</code>? I know that I have to use something like <code>docker inspect</code> but when I try to add that command, it only gets executed after I <code>^C</code> my script probably because docker has the execution. </p>
  
  <p>In <a href="https://stackoverflow.com/questions/24544288/how-to-detect-if-docker-run-succeeded-programmatically">this</a> answer, the docker is executed in some other script so it doesn't really work for my use case. </p>