我不完全确定这里发生了什么,但是当我在容器中运行代码时,似乎缓冲了stdout,但是如果我在主机或OSX上运行它,则不会.
https://github.com/myles-mcdonnell/procwrap/blob/master/procwrap.go
相关部分(为简洁起见而修改):
cmd := exec.Command("ping","127.0.0.1")
logger := &lumberjack.Logger{
Filename: conf.LogFile,MaxSize: conf.MaxLogSizeMb,MaxBackups: conf.MaxLogBackups,MaxAge: conf.MaxLogAgeDays,}
cmd.Stdout = io.MultiWriter(os.Stdout,logger)
err := cmd.Run()
在容器中运行子进程运行正常,但我只是间隔地看到输出(到stdout和日志文件),就像刷新缓冲区一样.在容器外部运行它,并在生成时输出.我正在使用1.6.3.我看到以交互方式和后台运行容器的相同行为.
Docker版本:
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
=======更新======
我看到基于基本图像的不同行为.在debian上运行procwrap:wheezy base我得到缓冲输出.在ubuntu上做同样的事情:相信它是同步的.下面的Dockerfiles,只需在每个上执行’docker run {image_name}’即可观察.在wheezy VM上运行procwrap(不涉及docker)不会缓冲输出.
可靠:
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
喘息:
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
最佳答案
原文链接:https://www.f2er.com/docker/435753.html