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

Method exec

pkg/composer/exec.go:86–119  ·  view source on GitHub ↗

exec constructs/executes the `nerdctl exec` command to be executed on the given container.

(ctx context.Context, container containerd.Container, eo ExecOptions)

Source from the content-addressed store, hash-verified

84
85// exec constructs/executes the `nerdctl exec` command to be executed on the given container.
86func (c *Composer) exec(ctx context.Context, container containerd.Container, eo ExecOptions) error {
87 args := []string{
88 "exec",
89 fmt.Sprintf("--detach=%t", eo.Detach),
90 fmt.Sprintf("--interactive=%t", eo.Interactive),
91 fmt.Sprintf("--tty=%t", eo.Tty),
92 fmt.Sprintf("--privileged=%t", eo.Privileged),
93 }
94 if eo.User != "" {
95 args = append(args, "--user", eo.User)
96 }
97 if eo.WorkDir != "" {
98 args = append(args, "--workdir", eo.WorkDir)
99 }
100 for _, e := range eo.Env {
101 args = append(args, "--env", e)
102 }
103 args = append(args, container.ID())
104 args = append(args, eo.Args...)
105 cmd := c.createNerdctlCmd(ctx, args...)
106
107 if eo.Interactive {
108 cmd.Stdin = os.Stdin
109 }
110 if !eo.Detach {
111 cmd.Stdout = os.Stdout
112 cmd.Stderr = os.Stderr
113 }
114
115 if c.DebugPrintFull {
116 log.G(ctx).Debugf("Executing %v", cmd.Args)
117 }
118 return cmd.Run()
119}

Callers 1

ExecMethod · 0.95

Calls 2

createNerdctlCmdMethod · 0.95
RunMethod · 0.65

Tested by

no test coverage detected