github.com/ruphin/docker@v1.10.1/daemon/pause.go (about)

     1  package daemon
     2  
     3  import (
     4  	"github.com/docker/docker/container"
     5  	derr "github.com/docker/docker/errors"
     6  )
     7  
     8  // ContainerPause pauses a container
     9  func (daemon *Daemon) ContainerPause(name string) error {
    10  	container, err := daemon.GetContainer(name)
    11  	if err != nil {
    12  		return err
    13  	}
    14  
    15  	if err := daemon.containerPause(container); err != nil {
    16  		return derr.ErrorCodePauseError.WithArgs(name, err)
    17  	}
    18  
    19  	return nil
    20  }
    21  
    22  // containerPause pauses the container execution without stopping the process.
    23  // The execution can be resumed by calling containerUnpause.
    24  func (daemon *Daemon) containerPause(container *container.Container) error {
    25  	container.Lock()
    26  	defer container.Unlock()
    27  
    28  	// We cannot Pause the container which is not running
    29  	if !container.Running {
    30  		return derr.ErrorCodeNotRunning.WithArgs(container.ID)
    31  	}
    32  
    33  	// We cannot Pause the container which is already paused
    34  	if container.Paused {
    35  		return derr.ErrorCodeAlreadyPaused.WithArgs(container.ID)
    36  	}
    37  
    38  	if err := daemon.execDriver.Pause(container.Command); err != nil {
    39  		return err
    40  	}
    41  	container.Paused = true
    42  	daemon.LogContainerEvent(container, "pause")
    43  	return nil
    44  }