title: How to run the docker commands from python?
body: <p>I want to run a set of docker commands from python.
  I tried creating a script like below and run the script from python using paramiko ssh_client to connect to the machine where the docker is running:</p>
  
  <pre><code>#!/bin/bash
  
     # Get container ID
     container_id="$(docker ps | grep hello | awk '{print $1}')"
  
     docker exec -it $container_id sh -c "cd /var/opt/bin/ &amp;&amp; echo $1 &amp;&amp; 
     echo $PWD &amp;&amp; ./test.sh -q $1"
  </code></pre>
  
  <p>But <code>docker exec ...</code> never gets executed.</p>
  
  <p>So I tried to run the below python script below, directly in the machine where the docker is running:
      import subprocess</p>
  
  <pre><code>docker_run = "docker exec 7f34a9c1b78f /bin/bash -c \"cd 
  /var/opt/bin/ &amp;&amp; ls -a\"".split()
  subprocess.call(docker_run, shell=True)
  </code></pre>
  
  <p>I get a message: "Usage:    docker COMMAND..."</p>
  
  <p>But I get the expected results if I run the command </p>
  
  <blockquote>
    <blockquote>
      <p>docker exec 7f34a9c1b78f /bin/bash -c "cd /var/opt/bin/ &amp;&amp; ls -a"
      directly in the machine</p>
    </blockquote>
  </blockquote>
  
  <p>How to run multiple docker commands from the python script? Thanks!</p>