Python noob here, I'm trying to use the exec_run
function from docker-py
to send commands to a detached docker container and have the output hitting stdout in real time. Here's a MWE:
import docker, sys
client = docker.from_env()
# start a detached container
box = client.containers.run(image = "ubuntu",
remove = True,
detach = True,
tty = True,
command = "/bin/bash")
# send a test command
box.exec_run(cmd = "find /") # gives no output in the terminal when run
# same again, but save the output
run = box.exec_run(cmd = "find /")
print(run.output.decode("utf-8"))
box.stop()
sys.exit()
I can grab the output after the fact by storing it in a variable, but I can't seem to get the real time output. I actually want to give it long running processes, so it's preferable to see the output as it happens (as well as saving it). Is this difficult to do, or am I missing something really basic here?