container_attach.go 921 B

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