title: Run a complex series of commands in the same Docker container
body: <p>I'm trying to automate the following loop with Docker: spawn a container, do some work inside of it (<em>more than one single command</em>), get some data out of the container.</p>
  
  <p>Something along the lines of:</p>
  
  <pre><code>for ( i = 0; i &lt; 10; i++ )
      spawn a container
      wget revision-i
      do something with it and store results in results.txt
  </code></pre>
  
  <p>According to the documentation I should go with:</p>
  
  <pre><code>for ( ... )
      docker run &lt;image&gt; &lt;long; list; of; instructions; separated; by; semicolon&gt;
  </code></pre>
  
  <p>Unfortunately, this approach is not attractive nor maintanable as the list of instructions grows in complexity.</p>
  
  <p>Wrapping the instructions in a script as in <code>docker run &lt;image&gt; /bin/bash script.sh</code> doesn't work either since I want to spawn a <strong>new</strong> container for every iteration of the loop.</p>
  
  <p>To sum up:</p>
  
  <ol>
  <li><p>Is there any sensible way to run a complex series of
  commands as described above inside the same container? </p></li>
  <li><p>Once some data are saved inside a container in, say, /home/results.txt,
  and the container returns, how do I get results.txt? The only way I
  can think of is to commit the container and tar the file out of the
  new image. Is there a more efficient way to do it?</p></li>
  </ol>
  
  <p>Bonus: should I use vanilla LXC instead? I don't have any experience with it though so I'm not sure.
  Thanks.</p>