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

Function runContainer

cli/command/container/run.go:121–267  ·  view source on GitHub ↗

nolint:gocyclo

(ctx context.Context, dockerCli command.Cli, runOpts *runOptions, copts *containerOptions, containerCfg *containerConfig)

Source from the content-addressed store, hash-verified

119
120//nolint:gocyclo
121func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOptions, copts *containerOptions, containerCfg *containerConfig) error {
122 config := containerCfg.Config
123 stdout, stderr := dockerCli.Out(), dockerCli.Err()
124 apiClient := dockerCli.Client()
125
126 config.ArgsEscaped = false
127
128 if !runOpts.detach {
129 if err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil {
130 return err
131 }
132 } else {
133 if copts.attach.Len() != 0 {
134 return errors.New("conflicting options: cannot specify both --attach and --detach")
135 }
136
137 config.AttachStdin = false
138 config.AttachStdout = false
139 config.AttachStderr = false
140 config.StdinOnce = false
141 }
142
143 detachKeys := runOpts.detachKeys
144 if detachKeys == "" {
145 detachKeys = dockerCli.ConfigFile().DetachKeys
146 }
147 if err := validateDetachKeys(runOpts.detachKeys); err != nil {
148 return err
149 }
150
151 containerID, err := createContainer(ctx, dockerCli, containerCfg, &runOpts.createOptions)
152 if err != nil {
153 return toStatusError(err)
154 }
155 if runOpts.sigProxy {
156 sigc := notifyAllSignals()
157 // since we're explicitly setting up signal handling here, and the daemon will
158 // get notified independently of the clients ctx cancellation, we use this context
159 // but without cancellation to avoid ForwardAllSignals from returning
160 // before all signals are forwarded.
161 bgCtx := context.WithoutCancel(ctx)
162 go ForwardAllSignals(bgCtx, apiClient, containerID, sigc)
163 defer signal.StopCatch(sigc)
164 }
165
166 ctx, cancelFun := context.WithCancel(context.WithoutCancel(ctx))
167 defer cancelFun()
168
169 var (
170 waitDisplayID chan struct{}
171 errCh chan error
172 )
173 attach := config.AttachStdin || config.AttachStdout || config.AttachStderr
174 if !attach {
175 // Make this asynchronous to allow the client to write to stdin before having to read the ID
176 waitDisplayID = make(chan struct{})
177 go func() {
178 defer close(waitDisplayID)

Callers 1

runRunFunction · 0.85

Calls 15

validateDetachKeysFunction · 0.85
createContainerFunction · 0.85
toStatusErrorFunction · 0.85
notifyAllSignalsFunction · 0.85
ForwardAllSignalsFunction · 0.85
attachContainerFunction · 0.85
waitExitOrRemovedFunction · 0.85
MonitorTtySizeFunction · 0.85
CheckTtyMethod · 0.80
ContainerStartMethod · 0.80
OutMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…