Skip to content

Commit 5251d37

Browse files
committed
cli/command: add EnvOverrideContext const for "DOCKER_CONTEXT"
Add a const for the name of the environment-variable we accept, so that we can document its purpose in code. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 7fae190 commit 5251d37

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

cli/command/cli.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ func (cli *DockerCli) ContextStore() store.Store {
370370
// order of preference:
371371
//
372372
// 1. The "--context" command-line option.
373-
// 2. The "DOCKER_CONTEXT" environment variable.
373+
// 2. The "DOCKER_CONTEXT" environment variable ([EnvOverrideContext]).
374374
// 3. The current context as configured through the in "currentContext"
375375
// field in the CLI configuration file ("~/.docker/config.json").
376376
// 4. If no context is configured, use the "default" context.
@@ -412,7 +412,7 @@ func resolveContextName(opts *cliflags.ClientOptions, config *configfile.ConfigF
412412
if os.Getenv(client.EnvOverrideHost) != "" {
413413
return DefaultContextName
414414
}
415-
if ctxName := os.Getenv("DOCKER_CONTEXT"); ctxName != "" {
415+
if ctxName := os.Getenv(EnvOverrideContext); ctxName != "" {
416416
return ctxName
417417
}
418418
if config != nil && config.CurrentContext != "" {

cli/command/defaultcontextstore.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import (
1111
const (
1212
// DefaultContextName is the name reserved for the default context (config & env based)
1313
DefaultContextName = "default"
14+
15+
// EnvOverrideContext is the name of the environment variable that can be
16+
// used to override the context to use. If set, it overrides the context
17+
// that's set in the CLI's configuration file, but takes no effect if the
18+
// "DOCKER_HOST" env-var is set (which takes precedence.
19+
EnvOverrideContext = "DOCKER_CONTEXT"
1420
)
1521

1622
// DefaultContext contains the default context data for all endpoints

0 commit comments

Comments
 (0)