diff --git a/components/engine/container.go b/components/engine/container.go index ef449653c4..0b54419122 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -357,14 +357,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } } else { go func() { - defer stdinCloser.Close() - - cStdout, err := container.StdoutPipe() - if err != nil { - utils.Debugf("Error stdout pipe") - return + if stdinCloser != nil { + defer stdinCloser.Close() + } + + if cStdout, err := container.StdoutPipe(); err != nil { + utils.Debugf("Error stdout pipe") + } else { + io.Copy(&utils.NopWriter{}, cStdout) } - io.Copy(&utils.NopWriter{}, cStdout) }() } if stderr != nil { @@ -394,14 +395,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } } else { go func() { - defer stdinCloser.Close() - - cStderr, err := container.StdoutPipe() - if err != nil { - utils.Debugf("Error stdout pipe") - return + if stdinCloser != nil { + defer stdinCloser.Close() + } + + if cStderr, err := container.StdoutPipe(); err != nil { + utils.Debugf("Error stdout pipe") + } else { + io.Copy(&utils.NopWriter{}, cStderr) } - io.Copy(&utils.NopWriter{}, cStderr) }() }