Reputation: 33
Python code that executes commands inside docker container using docker API and then reads output from them:
def foo(some_command_list, workdir):
output_list = []
output_byte_str = b''
for command in some_command_list:
cmd_output = container.exec_run(command, stream=True, workdir=workdir, tty=True)
for chunk in cmd_output.output:
output_byte_str += chunk
output_list.append(output_byte_str.decode('utf-8'))
return output_list
the stdout
(bool) and stderr
(bool) are set by default to true.
The following function returns a list of strings.
I would be grateful for any pointers.
Upvotes: 0
Views: 70