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

Function Stop

pkg/cmd/container/stop.go:34–63  ·  view source on GitHub ↗

Stop stops a list of containers specified by `reqs`.

(ctx context.Context, client *containerd.Client, reqs []string, opt types.ContainerStopOptions)

Source from the content-addressed store, hash-verified

32
33// Stop stops a list of containers specified by `reqs`.
34func Stop(ctx context.Context, client *containerd.Client, reqs []string, opt types.ContainerStopOptions) error {
35 walker := &containerwalker.ContainerWalker{
36 Client: client,
37 OnFound: func(ctx context.Context, found containerwalker.Found) error {
38 if found.MatchCount > 1 {
39 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
40 }
41 if err := cleanupNetwork(ctx, found.Container, opt.GOptions); err != nil {
42 return fmt.Errorf("unable to cleanup network for container: %s", found.Req)
43 }
44 if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, found.Container); err != nil {
45 return fmt.Errorf("unable to cleanup healthcheck timer for container: %s: %w", found.Req, err)
46 }
47 if err := containerutil.Stop(ctx, found.Container, opt.Timeout, opt.Signal); err != nil {
48 if errdefs.IsNotFound(err) {
49 fmt.Fprintf(opt.Stderr, "No such container: %s\n", found.Req)
50 return nil
51 }
52 return err
53 }
54 if err := ocihook.CleanupPortReserverProcess(opt.GOptions.Namespace, found.Container.ID()); err != nil {
55 return fmt.Errorf("unable to cleanup port reserver process for container: %s: %w", found.Req, err)
56 }
57 _, err := fmt.Fprintln(opt.Stdout, found.Req)
58 return err
59 },
60 }
61
62 return walker.WalkAll(ctx, reqs, true)
63}

Callers 1

stopActionFunction · 0.92

Calls 5

WalkAllMethod · 0.95
StopFunction · 0.92
cleanupNetworkFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…