github.com/olljanat/moby@v1.13.1/client/container_attach.go (about)

     1  package client
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/docker/docker/api/types"
     7  	"golang.org/x/net/context"
     8  )
     9  
    10  // ContainerAttach attaches a connection to a container in the server.
    11  // It returns a types.HijackedConnection with the hijacked connection
    12  // and the a reader to get output. It's up to the called to close
    13  // the hijacked connection by calling types.HijackedResponse.Close.
    14  func (cli *Client) ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) {
    15  	query := url.Values{}
    16  	if options.Stream {
    17  		query.Set("stream", "1")
    18  	}
    19  	if options.Stdin {
    20  		query.Set("stdin", "1")
    21  	}
    22  	if options.Stdout {
    23  		query.Set("stdout", "1")
    24  	}
    25  	if options.Stderr {
    26  		query.Set("stderr", "1")
    27  	}
    28  	if options.DetachKeys != "" {
    29  		query.Set("detachKeys", options.DetachKeys)
    30  	}
    31  	if options.Logs {
    32  		query.Set("logs", "1")
    33  	}
    34  
    35  	headers := map[string][]string{"Content-Type": {"text/plain"}}
    36  	return cli.postHijacked(ctx, "/containers/"+container+"/attach", query, nil, headers)
    37  }