container_attach.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package client
  2. import (
  3. "net/url"
  4. "github.com/docker/docker/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, container string, 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. if options.Logs {
  29. query.Set("logs", "1")
  30. }
  31. headers := map[string][]string{"Content-Type": {"text/plain"}}
  32. return cli.postHijacked(ctx, "/containers/"+container+"/attach", query, nil, headers)
  33. }