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

Function execActionWithContainer

pkg/cmd/container/exec.go:63–149  ·  view source on GitHub ↗
(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions)

Source from the content-addressed store, hash-verified

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)
65 if err != nil {
66 return err
67 }
68
69 task, err := container.Task(ctx, nil)
70 if err != nil {
71 return err
72 }
73 var (
74 ioCreator cio.Creator
75 in io.Reader
76 stdinC = &taskutil.StdinCloser{
77 Stdin: os.Stdin,
78 }
79 )
80
81 if options.Interactive {
82 in = stdinC
83 }
84 cioOpts := []cio.Opt{cio.WithStreams(in, os.Stdout, os.Stderr)}
85 if options.TTY {
86 cioOpts = append(cioOpts, cio.WithTerminal)
87 }
88 ioCreator = cio.NewCreator(cioOpts...)
89
90 execID := "exec-" + idgen.GenerateID()
91 process, err := task.Exec(ctx, execID, pspec, ioCreator)
92 if err != nil {
93 return err
94 }
95 stdinC.Closer = func() {
96 process.CloseIO(ctx, containerd.WithStdinCloser)
97 }
98 // if detach, we should not call this defer
99 if !options.Detach {
100 defer process.Delete(ctx)
101 }
102
103 statusC, err := process.Wait(ctx)
104 if err != nil {
105 return err
106 }
107
108 var con console.Console
109 if options.TTY {
110 con, err = consoleutil.Current()
111 if err != nil {
112 return err
113 }
114 defer con.Reset()
115 if _, err := term.MakeRaw(int(con.Fd())); err != nil {
116 return err
117 }
118 }
119 if !options.Detach {
120 if options.TTY {

Callers 1

ExecFunction · 0.85

Calls 13

GenerateIDFunction · 0.92
CurrentFunction · 0.92
HandleConsoleResizeFunction · 0.92
ForwardAllSignalsFunction · 0.92
StopCatchFunction · 0.92
generateExecProcessSpecFunction · 0.85
ExecMethod · 0.80
StartMethod · 0.80
DeleteMethod · 0.65
ResetMethod · 0.65
WaitMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…