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