diff --git a/api/context/context.go b/api/context/context.go index 6d03e159c..b0c1f64e9 100644 --- a/api/context/context.go +++ b/api/context/context.go @@ -21,13 +21,11 @@ import ( "golang.org/x/net/context" - configfile "github.com/docker/cli/cli/config/configfile" cliflags "github.com/docker/cli/cli/flags" ) type currentContextKey struct{} type cliOptionsKey struct{} -type configKey struct{} // WithCurrentContext sets the name of the current docker context func WithCurrentContext(ctx gocontext.Context, contextName string) context.Context { @@ -50,14 +48,3 @@ func CliOptions(ctx context.Context) cliflags.CommonOptions { cc, _ := ctx.Value(cliOptionsKey{}).(cliflags.CommonOptions) return cc } - -// WithConfig sets docker config -func WithConfig(ctx gocontext.Context, config configfile.ConfigFile) context.Context { - return context.WithValue(ctx, configKey{}, config) -} - -// Config returns the docker config -func Config(ctx context.Context) configfile.ConfigFile { - cc, _ := ctx.Value(cliOptionsKey{}).(configfile.ConfigFile) - return cc -} diff --git a/cli/main.go b/cli/main.go index 6812661df..3ce8b3d10 100644 --- a/cli/main.go +++ b/cli/main.go @@ -195,10 +195,6 @@ func main() { ctx = config.WithDir(ctx, configDir) currentContext := determineCurrentContext(opts.Context, configDir) - if len(opts.Hosts) > 0 { - opts.Context = "" - currentContext = "default" - } s, err := store.New(configDir) if err != nil { @@ -216,20 +212,26 @@ func main() { compose.Command(ctype), volume.Command(ctype), ) + if ctype == store.LocalContextType { + if len(opts.Hosts) > 0 { + opts.Context = "" + currentContext = "default" + } - cnxOptions := cliflags.CommonOptions{ - Context: opts.Context, - Debug: opts.Debug, - Hosts: opts.Hosts, - LogLevel: opts.LogLevel, - TLS: opts.TLS, - TLSVerify: opts.TLSVerify, - } + cnxOptions := cliflags.CommonOptions{ + Context: opts.Context, + Debug: opts.Debug, + Hosts: opts.Hosts, + LogLevel: opts.LogLevel, + TLS: opts.TLS, + TLSVerify: opts.TLSVerify, + } - if opts.TLSVerify { - cnxOptions.TLSOptions = opts.TLSOptions + if opts.TLSVerify { + cnxOptions.TLSOptions = opts.TLSOptions + } + ctx = apicontext.WithCliOptions(ctx, cnxOptions) } - ctx = apicontext.WithCliOptions(ctx, cnxOptions) ctx = apicontext.WithCurrentContext(ctx, currentContext) ctx = store.WithContextStore(ctx, s) diff --git a/local/e2e/cli-only/e2e_test.go b/local/e2e/cli-only/e2e_test.go index 8b8f1b75a..3d2b002e9 100644 --- a/local/e2e/cli-only/e2e_test.go +++ b/local/e2e/cli-only/e2e_test.go @@ -396,15 +396,15 @@ func TestLegacy(t *testing.T) { }) t.Run("host flag", func(t *testing.T) { - stderr := "nonexistent: Name or service not known" + stderr := "dial tcp: lookup nonexistent" if runtime.GOOS == "windows" { stderr = "error during connect: Get http://nonexitent:123" } res := c.RunDockerOrExitError("-H", "tcp://nonexistent:123", "version") res.Assert(t, icmd.Expected{ ExitCode: 1, - Err: stderr, }) + assert.Assert(t, strings.Contains(res.Stderr(), stderr), res.Stderr()) }) t.Run("existing contexts delegate", func(t *testing.T) {