resize.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package daemon
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/docker/docker/libcontainerd"
  6. )
  7. // ContainerResize changes the size of the TTY of the process running
  8. // in the container with the given name to the given height and width.
  9. func (daemon *Daemon) ContainerResize(name string, height, width int) error {
  10. container, err := daemon.GetContainer(name)
  11. if err != nil {
  12. return err
  13. }
  14. if !container.IsRunning() {
  15. return errNotRunning(container.ID)
  16. }
  17. if err = daemon.containerd.ResizeTerminal(context.Background(), container.ID, libcontainerd.InitProcessName, width, height); err == nil {
  18. attributes := map[string]string{
  19. "height": fmt.Sprintf("%d", height),
  20. "width": fmt.Sprintf("%d", width),
  21. }
  22. daemon.LogContainerEventWithAttributes(container, "resize", attributes)
  23. }
  24. return err
  25. }
  26. // ContainerExecResize changes the size of the TTY of the process
  27. // running in the exec with the given name to the given height and
  28. // width.
  29. func (daemon *Daemon) ContainerExecResize(name string, height, width int) error {
  30. ec, err := daemon.getExecConfig(name)
  31. if err != nil {
  32. return err
  33. }
  34. return daemon.containerd.ResizeTerminal(context.Background(), ec.ContainerID, ec.ID, width, height)
  35. }