Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Interactive Docker exec with docker-py

$
0
0

I'm trying to implement something equivalent to:

docker exec -it <some_container> /bin/bash

Ie. run a command in a container and connect stdin and stdout of my program to stdin and stdout of the command.

My reading of the documentation seems to imply that the following should do the job:

import dockerclient = docker.from_env()container, = client.containers.list()container.exec_run(['/usr/local/bin/bash'], stdin=True, tty=True)

(There's a single container running bash:latest)

But it doesn't seem like the program's stdin is connected to that of the exec'd command.The command line just sits there, echoing my input, but not reacting to it in any way.

I've also tried to interact with the raw socket:

_, s = container.exec_run(['/usr/local/bin/bash'], stdin=True, tty=True, socket=True)s.write('echo hello world')

But I'm getting UnsupportedOperation: File or stream is not writable.

Question: What would I have to do to allow the user of my code to interact with the std IO of a command executed in a container using docker-py?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>