Skip to content

Commit b127c9e

Browse files
committed
Fallback to default context when config file references a missing context
Previously, when the "CurrentContext" field of the config file referenced a context that did not exist in the store, the CLI would fail (even for simple things like docker context ls). This causes an issue with Docker Desktop "Contexts Syncing" feature (that uses the same store between win32 and WSL2): If win32 cli removes the "current context" of the WSL 2 CLI (which it can do if it is not the "current context" in the win32 config file), it would make the WSL 2 CLI unusable, asking the user to modify the config file by hand. This commit relaxes this behavior a bit: explicitly referencing a missing context (using the --context flag or DOCKER_CONTEXT env var) will still produce an error, but implicitly referencing such a missing context (via the CurrentContext config field) will fallback to use the "default" context. Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
1 parent af2c31c commit b127c9e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cli/command/cli.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,9 @@ func resolveContextName(opts *cliflags.CommonOptions, config *configfile.ConfigF
549549
if config != nil && config.CurrentContext != "" {
550550
_, err := contextstore.GetMetadata(config.CurrentContext)
551551
if store.IsErrContextDoesNotExist(err) {
552-
return "", errors.Errorf("Current context %q is not found on the file system, please check your config file at %s", config.CurrentContext, config.Filename)
552+
// If config file references a context that does not exist, fallback to default
553+
// Explicitly requested contexts (flag or env-var based) will still get the error
554+
return DefaultContextName, nil
553555
}
554556
return config.CurrentContext, err
555557
}

0 commit comments

Comments
 (0)