4

I am starting a docker container from a subprocess.Popen and it works, but when the script returns, the terminal settings of my shell are messed up. Nothing is echoed. I can fix this with tset in the terminal, but I don't want to require that. Has anyone here worked with docker and had seen and solved this issue?

Here is how I am starting the container:

        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.

Larry Martell
  • 3,526
  • 6
  • 40
  • 76
  • 3
    have you tried to remove `-t` and pass `stdin=DEVNULL`? [*"Specifying `-t` is forbidden when the client standard output is redirected or piped"*](https://docs.docker.com/engine/reference/run/) – jfs May 03 '16 at 20:41
  • Do you mean pass stdin=DEVNULL to Popen or to docker run? – Larry Martell May 03 '16 at 20:42
  • 3
    `Popen(.. stdin=subprocess.DEVNULL)` (so that no standard stream would be attached to the terminal) – jfs May 03 '16 at 20:45
  • `subprocess.DEVNULL` does not exist. I tried it with `stdin=None` and that, along with removing `-t` did the trick. You should make this an answer so I can upvote it. Thanks! – Larry Martell May 06 '16 at 15:31
  • `subprocess.DEVNULL` (have you tried to google it?) does exist in Python 3 and [it is easy to emulate it on Python 2](http://stackoverflow.com/q/11269575/4279). If you found a solution; you could post it as your own answer. – jfs May 06 '16 at 15:57
  • We're using 2.7. It works with None, so that's good enough for me. I wanted you to get the credit. If you don't want it I'll take it ;-) – Larry Martell May 06 '16 at 15:59
  • I know that you use Python 2.7; the question is tagged as such. I had hoped that you'll manage to put `subprocess.DEVNULL` into google yourself. `stdin=None` means a different thing. – jfs May 06 '16 at 16:09

1 Answers1

4

I fixed this by removing -t and passing in stdin=None. This was suggested by J.F. Sebastian in a comment, and he did not want to post it as an answer, so I am.

Larry Martell
  • 3,526
  • 6
  • 40
  • 76