title: Docker interactive mode and executing script
body: <p>I have a Python script in my docker container that needs to be executed, but I also need to have interactive access to the container once it has been created ( with /bin/bash ).</p>
  
  <p>I would like to be able to create my container, have my script executed and be inside the container to see the changes/results that have occurred (no need to manually execute my python script). </p>
  
  <p>The current issue I am facing is that if I use the CMD or ENTRYPOINT commands in the docker file I am unable to get back into the container once it has been created. I tried using docker start and docker attach but I'm getting the error:</p>
  
  <pre><code>sudo docker start containerID
  sudo docker attach containerID
  "You cannot attach to a stepped container, start it first"
  </code></pre>
  
  <p>Ideally, something close to this:</p>
  
  <pre><code>sudo docker run -i -t image /bin/bash python myscript.py
  </code></pre>
  
  <hr>
  
  <p>Assume my python script contains something like (It's irrelevant what it does, in this case it just creates a new file with text):</p>
  
  <pre><code>open('newfile.txt','w').write('Created new file with text\n')
  </code></pre>
  
  <p>When I create my container I want my script to execute and I would like to be able to see the content of the file. So something like:</p>
  
  <pre><code>root@66bddaa892ed# sudo docker run -i -t image /bin/bash
  bash4.1# ls
  newfile.txt
  bash4.1# cat newfile.txt
  Created new file with text
  bash4.1# exit
  root@66bddaa892ed#
  </code></pre>
  
  <p>In the example above my python script would have executed upon creation of the container to generate the new file newfile.txt. This is what I need.</p>