github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/daemon/resize.go (about)

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