github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/daemon/pause.go (about) 1 package daemon 2 3 import ( 4 "fmt" 5 6 "github.com/docker/docker/container" 7 ) 8 9 // ContainerPause pauses a container 10 func (daemon *Daemon) ContainerPause(name string) error { 11 container, err := daemon.GetContainer(name) 12 if err != nil { 13 return err 14 } 15 16 if err := daemon.containerPause(container); err != nil { 17 return err 18 } 19 20 return nil 21 } 22 23 // containerPause pauses the container execution without stopping the process. 24 // The execution can be resumed by calling containerUnpause. 25 func (daemon *Daemon) containerPause(container *container.Container) error { 26 container.Lock() 27 defer container.Unlock() 28 29 // We cannot Pause the container which is not running 30 if !container.Running { 31 return errNotRunning{container.ID} 32 } 33 34 // We cannot Pause the container which is already paused 35 if container.Paused { 36 return fmt.Errorf("Container %s is already paused", container.ID) 37 } 38 39 // We cannot Pause the container which is restarting 40 if container.Restarting { 41 return errContainerIsRestarting(container.ID) 42 } 43 44 if err := daemon.containerd.Pause(container.ID); err != nil { 45 return fmt.Errorf("Cannot pause container %s: %s", container.ID, err) 46 } 47 48 return nil 49 }