github.com/alexandrev/docker@v1.9.0/daemon/restart.go (about)

     1  package daemon
     2  
     3  import (
     4  	derr "github.com/docker/docker/errors"
     5  )
     6  
     7  // ContainerRestart stops and starts a container. It attempts to
     8  // gracefully stop the container within the given timeout, forcefully
     9  // stopping it if the timeout is exceeded. If given a negative
    10  // timeout, ContainerRestart will wait forever until a graceful
    11  // stop. Returns an error if the container cannot be found, or if
    12  // there is an underlying error at any stage of the restart.
    13  func (daemon *Daemon) ContainerRestart(name string, seconds int) error {
    14  	container, err := daemon.Get(name)
    15  	if err != nil {
    16  		return err
    17  	}
    18  	if err := container.Restart(seconds); err != nil {
    19  		return derr.ErrorCodeCantRestart.WithArgs(name, err)
    20  	}
    21  	return nil
    22  }