0

Looking for a solution to return the live output when executing commands inside a container using the .exec_run method.

** The scenario is for a currently running container **

Executing a command inside the container this way functions as expected.

run = container.exec_run(cmd='apt update')

We print that with .output method but this isn't a streamed 'live' output.

print(run.output.decode("utf-8"))

Would ideally like an output line for line to the console, with the ability to also dump it to a log file later, any solutions? Thanks

  • A typical setup is to run a network service (say, a Flask application) in your container; then you can make ordinary HTTP calls to it (perhaps using `requests`). `docker exec` is better reserved for debugging. – David Maze Nov 29 '20 at 13:13
  • So basically you're saying I'm thinking of docker-py in the wrong way? Container management yes but not system management within the container? Instead just make requests to a web application for running system tasks? – Paurini Wiringi Nov 29 '20 at 20:12
  • A container usually runs only one process; there's no "system management" _per se_. You could use docker-py for orchestration tasks (starting, stopping, deleting containers) but you shouldn't need it to interact with the process in the container. – David Maze Nov 29 '20 at 21:08
  • I do need to interact with processes running in the container though, so this would be the point of docker-py’s .exec_run method would it not? Likewise with docker exec via docker CLI. However, the goal is to retrieve a stream of output of that execution. – Paurini Wiringi Nov 30 '20 at 00:05

0 Answers0