Pipeing using exec_create, exec_start stdin, stdout
See original GitHub issueIf I use the docker CL this works perfectly for me.
echo "hello" | docker exec -i $3 sh -c 'cat >/text.txt'
Now I want to use docker-py and have this so far:
ex = cli.exec_create(container='nginx-ssl', cmd='cat >/carlskii.txt')
print cli.exec_inspect(ex)
ls = cli.exec_start(exec_id=ex["Id"], tty=True)
So how do I pass the “hello” or whatever data into the exec command so that it replicates the CL command ?
Incidentally this also works perfectly locally:
p = Popen(('docker', 'exec', '-i', 'nginx-ssl', 'sh', '-c', 'cat >text.txt'), stdin=subprocess.PIPE)
p.communicate('hello\n')
p.stdin.close()
Issue Analytics
- State:
- Created 8 years ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
How to write to stdin of a service - Unix & Linux Stack Exchange
You can just point ExecStart to a shell script that will set up the pipe and chainload the real executable. · I know...
Read more >How to Pipe Output to a File When Running as a Systemd ...
Try: ExecStart=/usr/bin/sh -c "/apppath/appname > /filepath/ ...
Read more >How to pipe Systemd service standard output from ExecStart ...
[Solved]-How to pipe Systemd service standard output from ExecStart to shell, ex. bash?-bash ... you can't really pipe stuff in ExecStart , but...
Read more >Docker exec API: using stdin to upload a file
Hi, A file can be uploaded to a container using the docker command line as follows echo bar > /tmp/foo.txt cat /tmp/foo.txt |...
Read more >Can systemd manage a pipeline? - Server Fault
My solution requires support for the fd option to StandardOutput= , which is available in (at least) systemd version 232 but not in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zbyte64 Could you provide a complete example here. I’m still struggling to get this to work.
Going back to my original question, I need to mimic this but using Python:
echo "hello" | docker exec -i $3 sh -c 'cat >/text.txt'
Sorry, let me clarify. To write to stdin one calls attach_socket with the appropriate flags:
But the socket you get back cannot be written to. Instead you must use os.write to send data to stdin:
This usage seems awkward. But If you use TLS then you instead do: