github.com/tompao/docker@v1.9.1/daemon/stop.go (about) 1 package daemon 2 3 import ( 4 derr "github.com/docker/docker/errors" 5 ) 6 7 // ContainerStop looks for the given container and terminates it, 8 // waiting the given number of seconds before forcefully killing the 9 // container. If a negative number of seconds is given, ContainerStop 10 // will wait for a graceful termination. An error is returned if the 11 // container is not found, is already stopped, or if there is a 12 // problem stopping the container. 13 func (daemon *Daemon) ContainerStop(name string, seconds int) error { 14 container, err := daemon.Get(name) 15 if err != nil { 16 return err 17 } 18 if !container.IsRunning() { 19 return derr.ErrorCodeStopped 20 } 21 if err := container.Stop(seconds); err != nil { 22 return derr.ErrorCodeCantStop.WithArgs(name, err) 23 } 24 return nil 25 }