Using the docker python SDK, I'm trying to pipe output of an echo command to exec_run as follows.
container.exec_run(['echo','5','|','python','test.py'])
the test.py has following code
s = input()
print(s)
The output that is produced is :
b'5 | python test.py\n'
I'm trying to mimic the following vanila linux command
echo "5" | python myscript.py
Try container.exec_run(['sh', '-c', 'echo 5 | python test.py'])
Thanks, @shin- This workaround works perfectly.But I used another hacky way to implement the same.
Thanks for the information.Will come handy in near future.
container.exec_run(['sh', '-c', 'echo 5 | python test.py']) in this command where to specify the container name?
@shin- Your workaround works great, it just solved a problem I have been facing for a few hours now, so thank you.
However, I don't understand why it is needed to prefix the required command with sh -c... If you have time to explain it would be appreciated, thanks again!
EDIT
I think I found the explanation here: https://askubuntu.com/a/230482
@mindcurv-nandaraj
client = docker.from_env()
container = client.containers.get('enter container ID here')
container.exec_run(...)
Most helpful comment
Try
container.exec_run(['sh', '-c', 'echo 5 | python test.py'])