I've posted this on StackOverflow too: https://stackoverflow.com/questions/45811792/piping-data-from-the-host-into-docker-container-command-not-working-with-docker/45917058
I'm running Docker on Windows 10 hosted using docker-machine. I'm trying to pipe data from host into a container spawn with 'docker run' with this command:
echo test | docker run -i ubuntu:16.04 cat -
I'd expect this command to output 'test' to the stdout, but all it does is print a blank line:
jannis MINGW64 ~
$ echo test | docker run -i ubuntu:16.04 cat -
jannis MINGW64 ~
$
However when I ssh into the docker-machine the command works as expected:
jannis MINGW64 ~
$ docker-machine ssh
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 17.06.1-ce, build HEAD : 80114bc - Fri Aug 18 17:58:04 UTC 2017
Docker version 17.06.1-ce, build 874a737
docker@default:~$ echo test | docker run -i ubuntu:16.04 cat -
test
Can someone tell me:
PS I'm using GitBash environment (based on MSYS2/MINGW) on my Windows 10 machine. Version info:
jannis MINGW64 ~
$ uname -a
MINGW64_NT-10.0 jannis 2.6.1(0.306/5/3) 2017-01-14 09:41 x86_64 Msys
jannis MINGW64 ~
$ docker version
Client:
Version: 17.06.0-ce
API version: 1.30
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:30:30 2017
OS/Arch: windows/amd64
Server:
Version: 17.06.1-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 874a737
Built: Thu Aug 17 22:54:55 2017
OS/Arch: linux/amd64
Experimental: false
For now I'm using a workaround. I'm saving the payload I want piped to a local file, then transferring the file into the container with docker cp
and next piping it locally within container.
To sum up:
What I want to do and doesn't work with docker-machine
is:
echo piped content | docker run -i ubuntu:16.04 cat -
Instead I do this:
jannis MINGW64 ~
$ docker create --name test-container ubuntu:16.04 sh -c 'cat - < /tmp/emulatedpipe'
a6eaf1e5f143113bcffa9df66a47b37c124cd34447b670480b5f096d45b7b162
jannis MINGW64 ~
$ echo piped content > emulatedpipe
jannis MINGW64 ~
$ docker cp emulatedpipe test-container:/tmp
jannis MINGW64 ~
$ docker start -i test-container
piped content
If you run with docker run -it
to also attach a tty does it work?
I'm pretty sure SSH allocates a TTY automatically, but if you pass -t
to the docker run this tells it to use a tty as well.
@dragon788 Doesn't work. This is what I get:
jannis MINGW64 ~
$ echo piped content | docker run -it ubuntu:16.04 cat -
unable to setup input stream: unable to set IO streams as raw terminal: Nieprawid艂owe doj艣cie.
PS I'm using ConEmu terminal
Oh it seems to be ConEmu-specific. I tried running the command in GitBash and it works:
jannis MINGW64 ~
$ echo piped content | docker run -i ubuntu:16.04 cat -
piped content
Looks like this might be related: https://github.com/moby/moby/issues/28814
With the workaround suggested in this comment I managed to make it work with ConEmu:
As a workaround, disabling ConEmu Settings -> Features -> ANSI and xterm sequences helped me.
Relevant ticket in ConEmu issue tracker: https://github.com/Maximus5/ConEmu/issues/958
Seems that this is a Docker issue.
Duplicate of moby/moby#28814
I was having this error, and then after doing @jannis-baratheon's ANSI fix I then received a different error:
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'.
As the error suggests, simply prefixing the command with 'winpty' makes things work in conemu. Thanks!
Bumping; -i
causes blank output, -t
causes @alexkb's error on Ubuntu (sans extra "mintty" message).
As of now it's not possible to both pipe data into a docker command and receive its output using just these flags. No clear indication how to do so otherwise.
Most helpful comment
Looks like this might be related: https://github.com/moby/moby/issues/28814
With the workaround suggested in this comment I managed to make it work with ConEmu: