ContainerStop looks for the given container and stops it. In case the container fails to stop gracefully within a time duration specified by the timeout argument, in seconds, it is forcefully terminated (killed). If the timeout is nil, the container's StopTimeout value is used, if set, otherwise th
(ctx context.Context, name string, options backend.ContainerStopOptions)
| 23 | // otherwise the engine default. A negative timeout value can be specified, |
| 24 | // meaning no timeout, i.e. no forceful termination is performed. |
| 25 | func (daemon *Daemon) ContainerStop(ctx context.Context, name string, options backend.ContainerStopOptions) error { |
| 26 | ctr, err := daemon.GetContainer(name) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | if !ctr.State.IsRunning() { |
| 31 | // This is not an actual error, but produces a 304 "not modified" |
| 32 | // when returned through the API to indicates the container is |
| 33 | // already in the desired state. It's implemented as an error |
| 34 | // to make the code calling this function terminate early (as |
| 35 | // no further processing is needed). |
| 36 | return errdefs.NotModified(errors.New("container is already stopped")) |
| 37 | } |
| 38 | err = daemon.containerStop(ctx, ctr, options) |
| 39 | if err != nil { |
| 40 | return errdefs.System(errors.Wrapf(err, "cannot stop container: %s", name)) |
| 41 | } |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | // containerStop sends a stop signal, waits, sends a kill signal. It uses |
| 46 | // a [context.WithoutCancel], so cancelling the context does not cancel |
nothing calls this directly
no test coverage detected