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

Function runDocker

cmd/docker/docker.go:475–553  ·  view source on GitHub ↗

nolint:gocyclo

(ctx context.Context, dockerCli *command.DockerCli)

Source from the content-addressed store, hash-verified

473
474//nolint:gocyclo
475func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
476 tcmd := newDockerCommand(dockerCli)
477
478 cmd, args, err := tcmd.HandleGlobalFlags()
479 if err != nil {
480 return err
481 }
482
483 if err := tcmd.Initialize(command.WithEnableGlobalMeterProvider(), command.WithEnableGlobalTracerProvider()); err != nil {
484 return err
485 }
486
487 mp := dockerCli.MeterProvider()
488 if mp, ok := mp.(command.MeterProvider); ok {
489 defer func() {
490 if err := mp.Shutdown(ctx); err != nil {
491 otel.Handle(err)
492 }
493 }()
494 } else {
495 _, _ = fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
496 }
497
498 dockerCli.InstrumentCobraCommands(ctx, cmd)
499
500 var envs []string
501 args, os.Args, envs, err = processAliases(dockerCli, cmd, args, os.Args)
502 if err != nil {
503 return err
504 }
505
506 if hasCompletionArg(args) {
507 // We add plugin command stubs early only for completion. We don't
508 // want to add them for normal command execution as it would cause
509 // a significant performance hit.
510 if err := pluginmanager.AddPluginCommandStubs(dockerCli, cmd); err != nil {
511 return err
512 }
513 }
514
515 var subCommand *cobra.Command
516 if len(args) > 0 {
517 ccmd, _, err := cmd.Find(args)
518 subCommand = ccmd
519 if err != nil || pluginmanager.IsPluginCommand(ccmd) {
520 err := tryPluginRun(ctx, dockerCli, cmd, args[0], envs)
521 if ccmd != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() && !errdefs.IsNotFound(err) {
522 errMessage := cmdErrorMessage(err)
523 pluginmanager.RunPluginHooks(ctx, dockerCli, cmd, ccmd, args, errMessage)
524 }
525 if err == nil {
526 return nil
527 }
528 if !errdefs.IsNotFound(err) {
529 // For plugin not found we fall through to
530 // cmd.Execute() which deals with reporting
531 // "command not found" in a consistent way.
532 return err

Callers 1

dockerMainFunction · 0.85

Calls 15

newDockerCommandFunction · 0.85
processAliasesFunction · 0.85
hasCompletionArgFunction · 0.85
tryPluginRunFunction · 0.85
cmdErrorMessageFunction · 0.85
HandleGlobalFlagsMethod · 0.80
HooksEnabledMethod · 0.80
SetArgsMethod · 0.80
MeterProviderMethod · 0.65
ShutdownMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…