MCPcopy Create free account
hub / github.com/containerd/nerdctl / stopContainers

Method stopContainers

pkg/composer/stop.go:57–85  ·  view source on GitHub ↗
(ctx context.Context, containers []containerd.Container, opt StopOptions)

Source from the content-addressed store, hash-verified

55}
56
57func (c *Composer) stopContainers(ctx context.Context, containers []containerd.Container, opt StopOptions) error {
58 var timeoutArg string
59 if opt.Timeout != nil {
60 // `nerdctl stop` uses `--time` instead of `--timeout`
61 timeoutArg = fmt.Sprintf("--time=%d", *opt.Timeout)
62 }
63
64 var rmWG sync.WaitGroup
65 for _, container := range containers {
66 container := container
67 rmWG.Add(1)
68 go func() {
69 defer rmWG.Done()
70 info, _ := container.Info(ctx, containerd.WithoutRefreshedMetadata)
71 log.G(ctx).Infof("Stopping container %s", info.Labels[labels.Name])
72 args := []string{"stop"}
73 if opt.Timeout != nil {
74 args = append(args, timeoutArg)
75 }
76 args = append(args, container.ID())
77 if err := c.runNerdctlCmd(ctx, args...); err != nil {
78 log.G(ctx).Warn(err)
79 }
80 }()
81 }
82 rmWG.Wait()
83
84 return nil
85}
86
87func (c *Composer) stopContainersFromParsedServices(ctx context.Context, containers map[string]serviceparser.Container) {
88 var rmWG sync.WaitGroup

Callers 3

StopMethod · 0.95
RemoveMethod · 0.95
DownMethod · 0.95

Calls 4

runNerdctlCmdMethod · 0.95
AddMethod · 0.80
InfoMethod · 0.80
WaitMethod · 0.45

Tested by

no test coverage detected