Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Piping data from the host into docker container command not working with docker machine #4235

Closed
jannis-baratheon opened this issue Aug 28, 2017 · 8 comments

Comments

@jannis-baratheon
Copy link

jannis-baratheon commented Aug 28, 2017

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

The problem

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:

  1. Why piping into a container within docker-machine doesn't work? Is this a bug?
  2. Is there a workaround for this (apart from the one provided above - ssh into the docker-machine VM)?

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

Current workaround

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
@dragon788
Copy link

dragon788 commented Oct 20, 2017

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.

@jannis-baratheon
Copy link
Author

jannis-baratheon commented Oct 23, 2017

@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

@jannis-baratheon
Copy link
Author

jannis-baratheon commented Oct 23, 2017

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

@jannis-baratheon
Copy link
Author

jannis-baratheon commented Oct 23, 2017

Looks like this might be related: moby/moby#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.

@jannis-baratheon
Copy link
Author

Relevant ticket in ConEmu issue tracker: Maximus5/ConEmu#958

Seems that this is a Docker issue.

@jannis-baratheon
Copy link
Author

jannis-baratheon commented Oct 23, 2017

Duplicate of moby/moby#28814

@alexkb
Copy link

alexkb commented Jul 3, 2018

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!

@Qix-
Copy link

Qix- commented Oct 21, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants