CurrentContext returns the current context name, based on flags, environment variables and the cli configuration file. It does not validate if the given context exists or if it's valid; errors may occur when trying to use it. Refer to [DockerCli.CurrentContext] above for further details.
(opts *cliflags.ClientOptions, cfg *configfile.ConfigFile)
| 437 | // |
| 438 | // Refer to [DockerCli.CurrentContext] above for further details. |
| 439 | func resolveContextName(opts *cliflags.ClientOptions, cfg *configfile.ConfigFile) string { |
| 440 | if opts != nil && opts.Context != "" { |
| 441 | return opts.Context |
| 442 | } |
| 443 | if opts != nil && len(opts.Hosts) > 0 { |
| 444 | return DefaultContextName |
| 445 | } |
| 446 | if os.Getenv(client.EnvOverrideHost) != "" { |
| 447 | return DefaultContextName |
| 448 | } |
| 449 | if ctxName := os.Getenv(EnvOverrideContext); ctxName != "" { |
| 450 | return ctxName |
| 451 | } |
| 452 | if cfg != nil && cfg.CurrentContext != "" { |
| 453 | // We don't validate if this context exists: errors may occur when trying to use it. |
| 454 | return cfg.CurrentContext |
| 455 | } |
| 456 | return DefaultContextName |
| 457 | } |
| 458 | |
| 459 | // DockerEndpoint returns the current docker endpoint |
| 460 | func (cli *DockerCli) DockerEndpoint() docker.Endpoint { |
no outgoing calls
no test coverage detected
searching dependent graphs…