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

Function attachContainer

cli/command/container/run.go:269–315  ·  view source on GitHub ↗
(ctx context.Context, dockerCli command.Cli, containerID string, errCh *chan error, config *container.Config, options client.ContainerAttachOptions)

Source from the content-addressed store, hash-verified

267}
268
269func attachContainer(ctx context.Context, dockerCli command.Cli, containerID string, errCh *chan error, config *container.Config, options client.ContainerAttachOptions) (func(), error) {
270 resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options)
271 if errAttach != nil {
272 return nil, errAttach
273 }
274
275 var (
276 out, cerr io.Writer
277 in io.ReadCloser
278 )
279 if options.Stdin {
280 in = dockerCli.In()
281 }
282 if options.Stdout {
283 out = dockerCli.Out()
284 }
285 if options.Stderr {
286 if config.Tty {
287 cerr = dockerCli.Out()
288 } else {
289 cerr = dockerCli.Err()
290 }
291 }
292
293 ch := make(chan error, 1)
294 *errCh = ch
295
296 go func() {
297 ch <- func() error {
298 streamer := hijackedIOStreamer{
299 streams: dockerCli,
300 inputStream: in,
301 outputStream: out,
302 errorStream: cerr,
303 resp: resp.HijackedResponse,
304 tty: config.Tty,
305 detachKeys: options.DetachKeys,
306 }
307
308 if errHijack := streamer.stream(ctx); errHijack != nil {
309 return errHijack
310 }
311 return errAttach
312 }()
313 }()
314 return resp.HijackedResponse.Close, nil
315}
316
317// withHelp decorates the error with a suggestion to use "--help".
318func withHelp(err error, commandName string) error {

Callers 1

runContainerFunction · 0.85

Calls 6

streamMethod · 0.95
ContainerAttachMethod · 0.80
ClientMethod · 0.65
InMethod · 0.65
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…