Search code examples
linuxdockerpipedocker-machine

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


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

Solution

  • EDIT 2-11-2017

    Turns out it was a problem with the terminal I'm using (ConEmu). Or to be more exact the special case in Docker's codebase dedicated to ConEmu.

    Following the workaround suggested in this comment I managed to make piping work:

    As a workaround, disabling ConEmu Settings -> Features -> ANSI and xterm sequences helped me.

    Relevant links:

    ORIGINAL ANSWER

    I've posted a bug in docker-machine's issuetracker, we'll see what they say.

    Currently I've ended up with 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