# Starting docker container from python script

**URL:** <https://forums.docker.com/t/starting-docker-container-from-python-script/10677>\
**Category:** General\
**Tags:** docker\
**Created:** [May 2, 2016, 1:46pm UTC](https://forums.docker.com/t/starting-docker-container-from-python-script/10677 "2016-05-02T13:46:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![larrymartell59](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/larrymartell59/32/6866_2.png) [@larrymartell59](https://forums.docker.com/u/larrymartell59)\
**Post date:** [May 2, 2016, 1:46pm UTC](https://forums.docker.com/t/starting-docker-container-from-python-script/10677/1 "2016-05-02T13:46:06Z")

</div>

I want to start my container from a python script. I am doing that using subprocess.Popen. It works fine, but when the python script returns, the terminal settings of my shell are messed up. Nothing is echoed and return doesn’t cause a newline. I can fix this with ‘tset’ in the terminal, but I don’t want to require that. Has anyone seen and solved this issue?

---

<div class="post-metadata">

**Author:** ![dmaze](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@dmaze](https://forums.docker.com/u/dmaze)\
**Post date:** [May 2, 2016, 4:56pm UTC](https://forums.docker.com/t/starting-docker-container-from-python-script/10677/2 "2016-05-02T16:56:32Z")

</div>

I `docker run` things in Python build scripts all the time and don’t have issues like what you describe. Can you give more details, like which containers you’re running and what arguments you’ve giving to `docker run`?

---

<div class="post-metadata">

**Author:** ![larrymartell59](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/larrymartell59/32/6866_2.png) [@larrymartell59](https://forums.docker.com/u/larrymartell59)\
**Post date:** [May 2, 2016, 5:00pm UTC](https://forums.docker.com/t/starting-docker-container-from-python-script/10677/3 "2016-05-02T17:00:23Z")

</div>

`cmd = ['sudo', 'docker', 'run', '-t', '-i', 'elucidbio/capdata:v2', 'bash'] p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)`

I have tried replacing the bash with an infinite loop and using nohup, but the same thing happened.

---

<div class="post-metadata">

**Author:** ![rizwan2k10](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@rizwan2k10](https://forums.docker.com/u/rizwan2k10)\
**Post date:** [June 12, 2018, 4:49am UTC](https://forums.docker.com/t/starting-docker-container-from-python-script/10677/4 "2018-06-12T04:49:32Z")

</div>

remove interactive or -i option, You should be able to run in non interactive mode
