from subprocess import Popen, PIPE p = Popen("docker run -i -t --name="%s" dockerfile/python /bin/bash", stdin=PIPE) p.communicate("timeout 0.5 python | head -n 500000 " % run_this)