resize.go 1.1 KB

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