restart.go 790 B

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