nolint:gocyclo
(ctx context.Context, dockerCli command.Cli, runOpts *runOptions, copts *containerOptions, containerCfg *containerConfig)
| 119 | |
| 120 | //nolint:gocyclo |
| 121 | func 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) |
no test coverage detected
searching dependent graphs…