title: Best way to stop Docker container in Jenkins
body: <p>I have a CI-server (jenkins) which is building new Docker images.
  Now I want to run a new Docker container when the build is succesful.
  But therefor I have to stop the previous running container.</p>
  
  <p>What's the best way to perform this?
  <code>localhost:5000/test/myapp:"${BUILD_ID}</code> is the name of my new images. So I'm using the build-id as tag. First I thought to perform:</p>
  
  <pre><code>docker stop localhost:5000/dbm/my-php-app:${BUILD_ID-1}
  </code></pre>
  
  <p>But this isn't a right solution because when a build would fail, this would be wrong. </p>
  
  <pre><code>Build 1: succes -&gt; run container 1 
  Build 2: failed -&gt; run container 1
  Build 3: succes -&gt; stop container (3-1) =2 --&gt; wrong (isn't running)
  </code></pre>
  
  <p>What could be a solution? Proposals where I have to change the tag-idea are also welcome</p>