github.com/docker/engine@v22.0.0-20211208180946-d456264580cf+incompatible/daemon/resize.go (about) 1 package daemon // import "github.com/docker/docker/daemon" 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 libcontainerdtypes "github.com/docker/docker/libcontainerd/types" 9 ) 10 11 // ContainerResize changes the size of the TTY of the process running 12 // in the container with the given name to the given height and width. 13 func (daemon *Daemon) ContainerResize(name string, height, width int) error { 14 container, err := daemon.GetContainer(name) 15 if err != nil { 16 return err 17 } 18 19 if !container.IsRunning() { 20 return errNotRunning(container.ID) 21 } 22 23 if err = daemon.containerd.ResizeTerminal(context.Background(), container.ID, libcontainerdtypes.InitProcessName, width, height); err == nil { 24 attributes := map[string]string{ 25 "height": fmt.Sprintf("%d", height), 26 "width": fmt.Sprintf("%d", width), 27 } 28 daemon.LogContainerEventWithAttributes(container, "resize", attributes) 29 } 30 return err 31 } 32 33 // ContainerExecResize changes the size of the TTY of the process 34 // running in the exec with the given name to the given height and 35 // width. 36 func (daemon *Daemon) ContainerExecResize(name string, height, width int) error { 37 ec, err := daemon.getExecConfig(name) 38 if err != nil { 39 return err 40 } 41 42 // TODO: the timeout is hardcoded here, it would be more flexible to make it 43 // a parameter in resize request context, which would need API changes. 44 timeout := time.NewTimer(10 * time.Second) 45 defer timeout.Stop() 46 47 select { 48 case <-ec.Started: 49 return daemon.containerd.ResizeTerminal(context.Background(), ec.ContainerID, ec.ID, width, height) 50 case <-timeout.C: 51 return fmt.Errorf("timeout waiting for exec session ready") 52 } 53 }