title: Stop and delete Docker container if it's running
body: <p>I am looking to pragmatically stop and delete a Docker container if it is running.  This is for a build script.</p>
  <p>Take the following example.  How would I stop and delete the Docker container &quot;rabbitmq&quot; as seen under the NAMES column in a bash script?</p>
  <pre><code>docker ps
  
  CONTAINER ID        IMAGE             COMMAND                  CREATED             STATUS              PORTS                   NAMES
  9909a5e2856f        rabbitmq-image   &quot;/docker-entrypoint.s&quot;   11 minutes ago      Up 11 minutes       0.0.0.0:5672-&gt;5672/tcp, rabbitmq
  8990dd1fe503        redis-image      &quot;/entrypoint.sh redis&quot;   6 weeks ago         Up 4 days           0.0.0.0:32770-&gt;6379/tcp redis
  etc 
  </code></pre>
  <p>The following command will delete the container and does what I'm looking to do</p>
  <pre><code>docker stop rabbitmq &amp;&amp; docker rm -f rabbitmq
  </code></pre>
  <p>However, it's combing it into a script that I would like to know? I think it would look something like this.</p>
  <pre><code>#!/bin/bash
  
  if [ /*docker ps check some value */ ]; then
     docker stop rabbitmq &amp;&amp; docker rm -f rabbitmq
  fi
  </code></pre>