container_resize.go 929 B

123456789101112131415161718192021222324252627282930
  1. package client
  2. import (
  3. "net/url"
  4. "strconv"
  5. "github.com/docker/engine-api/types"
  6. "golang.org/x/net/context"
  7. )
  8. // ContainerResize changes the size of the tty for a container.
  9. func (cli *Client) ContainerResize(ctx context.Context, options types.ResizeOptions) error {
  10. return cli.resize(ctx, "/containers/"+options.ID, options.Height, options.Width)
  11. }
  12. // ContainerExecResize changes the size of the tty for an exec process running inside a container.
  13. func (cli *Client) ContainerExecResize(ctx context.Context, options types.ResizeOptions) error {
  14. return cli.resize(ctx, "/exec/"+options.ID, options.Height, options.Width)
  15. }
  16. func (cli *Client) resize(ctx context.Context, basePath string, height, width int) error {
  17. query := url.Values{}
  18. query.Set("h", strconv.Itoa(height))
  19. query.Set("w", strconv.Itoa(width))
  20. resp, err := cli.post(ctx, basePath+"/resize", query, nil, nil)
  21. ensureReaderClosed(resp)
  22. return err
  23. }