container_attach.go 978 B

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