Add warnings when DOCKER_HOST conflicts with contexts
For clarity, on `docker context use` or `docker context ls`, this adds a warning if the DOCKER_HOST variable is set because it overrides the active context. Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
This commit is contained in:
@ -2,6 +2,7 @@ package context
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
@ -39,5 +40,9 @@ func RunUse(dockerCli command.Cli, name string) error {
|
||||
}
|
||||
fmt.Fprintln(dockerCli.Out(), 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user