mirror of https://github.com/docker/cli.git
Merge pull request #1817 from simonferquel/docker-host-context-warning
Add warnings when DOCKER_HOST conflicts with contexts
This commit is contained in:
commit
ac758d9f80
|
@ -2,6 +2,7 @@ package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
|
@ -76,7 +77,14 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
|
||||||
sort.Slice(contexts, func(i, j int) bool {
|
sort.Slice(contexts, func(i, j int) bool {
|
||||||
return sortorder.NaturalLess(contexts[i].Name, contexts[j].Name)
|
return sortorder.NaturalLess(contexts[i].Name, contexts[j].Name)
|
||||||
})
|
})
|
||||||
return format(dockerCli, opts, contexts)
|
if err := format(dockerCli, opts, contexts); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if os.Getenv("DOCKER_HOST") != "" {
|
||||||
|
fmt.Fprint(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
|
||||||
|
"To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.\n")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func format(dockerCli command.Cli, opts *listOptions, contexts []*formatter.ClientContext) error {
|
func format(dockerCli command.Cli, opts *listOptions, contexts []*formatter.ClientContext) error {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -39,5 +40,9 @@ func RunUse(dockerCli command.Cli, name string) error {
|
||||||
}
|
}
|
||||||
fmt.Fprintln(dockerCli.Out(), name)
|
fmt.Fprintln(dockerCli.Out(), name)
|
||||||
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
|
fmt.Fprintf(dockerCli.Err(), "Current context is now %q\n", name)
|
||||||
|
if os.Getenv("DOCKER_HOST") != "" {
|
||||||
|
fmt.Fprintf(dockerCli.Err(), "Warning: DOCKER_HOST environment variable overrides the active context. "+
|
||||||
|
"To use %q, either set the global --context flag, or unset DOCKER_HOST environment variable.\n", name)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue