github.com/amylindburg/docker@v1.7.0/daemon/attach.go (about)

     1  package daemon
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/docker/docker/pkg/stdcopy"
     7  )
     8  
     9  type ContainerAttachWithLogsConfig struct {
    10  	InStream                       io.ReadCloser
    11  	OutStream                      io.Writer
    12  	UseStdin, UseStdout, UseStderr bool
    13  	Logs, Stream                   bool
    14  	Multiplex                      bool
    15  }
    16  
    17  func (daemon *Daemon) ContainerAttachWithLogs(name string, c *ContainerAttachWithLogsConfig) error {
    18  	container, err := daemon.Get(name)
    19  	if err != nil {
    20  		return err
    21  	}
    22  
    23  	var errStream io.Writer
    24  
    25  	if !container.Config.Tty && c.Multiplex {
    26  		errStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stderr)
    27  		c.OutStream = stdcopy.NewStdWriter(c.OutStream, stdcopy.Stdout)
    28  	} else {
    29  		errStream = c.OutStream
    30  	}
    31  
    32  	var stdin io.ReadCloser
    33  	var stdout, stderr io.Writer
    34  
    35  	if c.UseStdin {
    36  		stdin = c.InStream
    37  	}
    38  	if c.UseStdout {
    39  		stdout = c.OutStream
    40  	}
    41  	if c.UseStderr {
    42  		stderr = errStream
    43  	}
    44  
    45  	return container.AttachWithLogs(stdin, stdout, stderr, c.Logs, c.Stream)
    46  }
    47  
    48  type ContainerWsAttachWithLogsConfig struct {
    49  	InStream             io.ReadCloser
    50  	OutStream, ErrStream io.Writer
    51  	Logs, Stream         bool
    52  }
    53  
    54  func (daemon *Daemon) ContainerWsAttachWithLogs(name string, c *ContainerWsAttachWithLogsConfig) error {
    55  	container, err := daemon.Get(name)
    56  	if err != nil {
    57  		return err
    58  	}
    59  
    60  	return container.AttachWithLogs(c.InStream, c.OutStream, c.ErrStream, c.Logs, c.Stream)
    61  }