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

Function Exec

pkg/cmd/container/exec.go:43–61  ·  view source on GitHub ↗

Exec will find the right running container to run a new command.

(ctx context.Context, client *containerd.Client, args []string, options types.ContainerExecOptions)

Source from the content-addressed store, hash-verified

41
42// Exec will find the right running container to run a new command.
43func Exec(ctx context.Context, client *containerd.Client, args []string, options types.ContainerExecOptions) error {
44 walker := &containerwalker.ContainerWalker{
45 Client: client,
46 OnFound: func(ctx context.Context, found containerwalker.Found) error {
47 if found.MatchCount > 1 {
48 return fmt.Errorf("multiple IDs found with provided prefix: %s", found.Req)
49 }
50 return execActionWithContainer(ctx, client, found.Container, args, options)
51 },
52 }
53 req := args[0]
54 n, err := walker.Walk(ctx, req)
55 if err != nil {
56 return err
57 } else if n == 0 {
58 return fmt.Errorf("no such container %s", req)
59 }
60 return nil
61}
62
63func execActionWithContainer(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions) error {
64 pspec, err := generateExecProcessSpec(ctx, client, container, args, options)

Callers 1

execActionFunction · 0.92

Calls 2

WalkMethod · 0.95
execActionWithContainerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…