diff --git a/commands.go b/commands.go index ee481fd282..299ae0e4f5 100644 --- a/commands.go +++ b/commands.go @@ -874,7 +874,6 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) if !config.Detach { var attachErr chan error if config.OpenStdin { - config.StdinOnce = true Debugf("Attaching with stdin\n") attachErr = container.Attach(stdin, stdout, stdout) } else { diff --git a/container.go b/container.go index 4f320f32fd..a11539180e 100644 --- a/container.go +++ b/container.go @@ -101,6 +101,10 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) { Cmd: runCmd, Image: image, } + // When allocating stdin in attached mode, close stdin at client disconnect + if config.OpenStdin && !config.Detach { + config.StdinOnce = true + } return config, nil }