@@ -210,7 +210,13 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
210210 cli .configFile = cliconfig .LoadDefaultConfigFile (cli .err )
211211
212212 if cli .client == nil {
213- cli .contextStore = store .New (cliconfig .ContextStoreDir (), cli .contextStoreConfig )
213+ baseContextSore := store .New (cliconfig .ContextStoreDir (), cli .contextStoreConfig )
214+ cli .contextStore = & ContextStoreWithDefault {
215+ Store : baseContextSore ,
216+ Resolver : func () (* DefaultContext , error ) {
217+ return resolveDefaultContext (opts .Common , cli .ConfigFile (), cli .Err ())
218+ },
219+ }
214220 cli .currentContext , err = resolveContextName (opts .Common , cli .configFile , cli .contextStore )
215221 if err != nil {
216222 return err
@@ -280,7 +286,7 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF
280286}
281287
282288func resolveDockerEndpoint (s store.Store , contextName string , opts * cliflags.CommonOptions ) (docker.Endpoint , error ) {
283- if contextName != "" {
289+ if contextName != "" || contextName == DefaultContextName {
284290 ctxMeta , err := s .GetContextMetadata (contextName )
285291 if err != nil {
286292 return docker.Endpoint {}, err
@@ -291,6 +297,10 @@ func resolveDockerEndpoint(s store.Store, contextName string, opts *cliflags.Com
291297 }
292298 return docker .WithTLSData (s , contextName , epMeta )
293299 }
300+ return resolveDefaultDockerEndpoint (opts )
301+ }
302+
303+ func resolveDefaultDockerEndpoint (opts * cliflags.CommonOptions ) (docker.Endpoint , error ) {
294304 host , err := getServerHost (opts .Hosts , opts .TLSOptions )
295305 if err != nil {
296306 return docker.Endpoint {}, err
@@ -396,7 +406,7 @@ func (cli *DockerCli) StackOrchestrator(flagValue string) (Orchestrator, error)
396406 if currentContext == "" {
397407 currentContext = configFile .CurrentContext
398408 }
399- if currentContext != "" {
409+ if currentContext != "" && currentContext != DefaultContextName {
400410 contextstore := cli .contextStore
401411 if contextstore == nil {
402412 contextstore = store .New (cliconfig .ContextStoreDir (), cli .contextStoreConfig )
@@ -508,7 +518,7 @@ func resolveContextName(opts *cliflags.CommonOptions, config *configfile.ConfigF
508518 if opts .Context != "" && len (opts .Hosts ) > 0 {
509519 return "" , errors .New ("Conflicting options: either specify --host or --context, not both" )
510520 }
511- if opts .Context != "" {
521+ if opts .Context != "" && opts . Context != DefaultContextName {
512522 return opts .Context , nil
513523 }
514524 if len (opts .Hosts ) > 0 {
0 commit comments