MCPcopy
hub / github.com/docker/compose / stopContainer

Method stopContainer

pkg/compose/down.go:298–324  ·  pkg/compose/down.go::composeService.stopContainer
(ctx context.Context, service *types.ServiceConfig, ctr containerType.Summary, timeout *time.Duration, listener api.ContainerEventListener)

Source from the content-addressed store, hash-verified

296}
297
298func (s *composeService) stopContainer(ctx context.Context, service *types.ServiceConfig, ctr containerType.Summary, timeout *time.Duration, listener api.ContainerEventListener) error {
299 eventName := getContainerProgressName(ctr)
300 s.events.On(newEvent(eventName, api.Working, api.StatusStopping))
301
302 if service != nil {
303 for _, hook := range service.PreStop {
304 err := s.runHook(ctx, ctr, *service, hook, listener)
305 if err != nil {
306 // Ignore errors indicating that some containers were already stopped or removed.
307 if errdefs.IsNotFound(err) || errdefs.IsConflict(err) {
308 return nil
309 }
310 return err
311 }
312 }
313 }
314
315 _, err := s.apiClient().ContainerStop(ctx, ctr.ID, client.ContainerStopOptions{
316 Timeout: utils.DurationSecondToInt(timeout),
317 })
318 if err != nil {
319 s.events.On(errorEvent(eventName, "Error while Stopping"))
320 return err
321 }
322 s.events.On(newEvent(eventName, api.Done, api.StatusStopped))
323 return nil
324}
325
326func (s *composeService) stopContainers(ctx context.Context, serv *types.ServiceConfig, containers []containerType.Summary, timeout *time.Duration, listener api.ContainerEventListener) error {
327 eg, ctx := errgroup.WithContext(ctx)

Callers 2

stopContainersMethod · 0.95

Calls 8

runHookMethod · 0.95
apiClientMethod · 0.95
DurationSecondToIntFunction · 0.92
getContainerProgressNameFunction · 0.85
newEventFunction · 0.85
errorEventFunction · 0.85
OnMethod · 0.65
ContainerStopMethod · 0.45

Tested by

no test coverage detected