stdout being buffered in docker container
<p>I'm not entirely sure what is going on here but it appears that stdout is being buffered when I run my code in a container, but not if I run it on the host or on OSX.</p>

<p><a href="https://github.com/myles-mcdonnell/procwrap/blob/master/procwrap.go" rel="noreferrer">https://github.com/myles-mcdonnell/procwrap/blob/master/procwrap.go</a></p>

<p>The relevant piece (modified for brevity):</p>

<pre><code>    cmd := exec.Command("ping", "127.0.0.1")

    logger := &amp;lumberjack.Logger{
        Filename:   conf.LogFile,
        MaxSize:    conf.MaxLogSizeMb,
        MaxBackups: conf.MaxLogBackups,
        MaxAge:     conf.MaxLogAgeDays,
    }

    cmd.Stdout = io.MultiWriter(os.Stdout, logger)  

    err := cmd.Run()
</code></pre>

<p>Running in a container the sub process runs fine but I only see output (to stdout and the log file) at intervals, like a buffer is being flushed.  Run it outside of a container and it outputs as it is generated. I'm using go 1.6.3.  I see the same behaviour running the container interactively and in the background.</p>

<p>Docker version:</p>

<pre><code>Client:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 21:49:11 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 23:54:00 2016
 OS/Arch:      linux/amd64
</code></pre>

<p>======= UPDATE ======</p>

<p>I'm seeing different behaviour based on the base image.  Running procwrap on a debian:wheezy base I get buffered output.  Doing the same on ubuntu:trusty it's synchronous.  Dockerfiles below, simply execute 'docker run {image_name}' on each to observe.  Run procwrap on a wheezy VM (no docker involved) does not buffer the output.</p>

<p>TRUSTY:</p>

<pre><code>FROM ubuntu:trusty
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git
RUN curl -O https://storage.googleapis.com/golang/go1.6.3.linux-amd64.tar.gz
RUN tar -xvf go1.6.3.linux-amd64.tar.gz
RUN mv go /usr/local
ENV GOROOT=/usr/local/go
RUN mkdir -p /go/src/github.com/myles-mcdonnell
ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin:$GOROOT/bin
RUN go get github.com/myles-mcdonnell/procwrap
WORKDIR /go/src/github.com/myles-mcdonnell/procwrap
CMD procwrap -v
</code></pre>

<p>WHEEZY:</p>

<pre><code>FROM debian:wheezy
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git
RUN curl -O https://storage.googleapis.com/golang/go1.6.3.linux-amd64.tar.gz
RUN tar -xvf go1.6.3.linux-amd64.tar.gz
RUN mv go /usr/local
ENV GOROOT=/usr/local/go
RUN mkdir -p /go/src/github.com/myles-mcdonnell
ENV GOPATH=/go
ENV PATH=$PATH:$GOPATH/bin:$GOROOT/bin
RUN go get github.com/myles-mcdonnell/procwrap
WORKDIR /go/src/github.com/myles-mcdonnell/procwrap
CMD procwrap -v
</code></pre>