MCPcopy Index your code
hub / github.com/docker/cli / RunExec

Function RunExec

cli/command/container/exec.go:88–130  ·  view source on GitHub ↗

RunExec executes an `exec` command

(ctx context.Context, dockerCLI command.Cli, containerIDorName string, options ExecOptions)

Source from the content-addressed store, hash-verified

86
87// RunExec executes an `exec` command
88func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName string, options ExecOptions) error {
89 execOptions, err := parseExec(options, dockerCLI.ConfigFile())
90 if err != nil {
91 return err
92 }
93
94 apiClient := dockerCLI.Client()
95
96 // We need to check the tty _before_ we do the ContainerExecCreate, because
97 // otherwise if we error out we will leak execIDs on the server (and
98 // there's no easy way to clean those up). But also in order to make "not
99 // exist" errors take precedence we do a dummy inspect first.
100 if _, err := apiClient.ContainerInspect(ctx, containerIDorName, client.ContainerInspectOptions{}); err != nil {
101 return err
102 }
103 if !options.Detach {
104 if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.TTY); err != nil {
105 return err
106 }
107 }
108
109 fillConsoleSize(execOptions, dockerCLI)
110
111 response, err := apiClient.ExecCreate(ctx, containerIDorName, *execOptions)
112 if err != nil {
113 return err
114 }
115
116 execID := response.ID
117 if execID == "" {
118 return errors.New("exec ID empty")
119 }
120
121 if options.Detach {
122 _, err := apiClient.ExecStart(ctx, execID, client.ExecStartOptions{
123 Detach: options.Detach,
124 TTY: execOptions.TTY,
125 ConsoleSize: client.ConsoleSize{Height: execOptions.ConsoleSize.Height, Width: execOptions.ConsoleSize.Width},
126 })
127 return err
128 }
129 return interactiveExec(ctx, dockerCLI, execOptions, execID)
130}
131
132func fillConsoleSize(execOptions *client.ExecCreateOptions, dockerCli command.Cli) {
133 if execOptions.TTY {

Callers 2

TestRunExecFunction · 0.85
newExecCommandFunction · 0.85

Calls 10

parseExecFunction · 0.85
fillConsoleSizeFunction · 0.85
interactiveExecFunction · 0.85
ContainerInspectMethod · 0.80
CheckTtyMethod · 0.80
ExecCreateMethod · 0.80
ExecStartMethod · 0.80
ConfigFileMethod · 0.65
ClientMethod · 0.65
InMethod · 0.65

Tested by 1

TestRunExecFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…