diff --git a/cli/command/registry/login.go b/cli/command/registry/login.go index ce5e584859..3679e51edd 100644 --- a/cli/command/registry/login.go +++ b/cli/command/registry/login.go @@ -110,6 +110,9 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err if err := verifyLoginOptions(dockerCLI, &opts); err != nil { return err } + + maybePrintEnvAuthWarning(dockerCLI) + var ( serverAddress string msg string diff --git a/cli/command/registry/logout.go b/cli/command/registry/logout.go index 6dc75dc585..2af2cdad3f 100644 --- a/cli/command/registry/logout.go +++ b/cli/command/registry/logout.go @@ -36,6 +36,8 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command { } func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error { + maybePrintEnvAuthWarning(dockerCLI) + var isDefaultRegistry bool if serverAddress == "" { diff --git a/cli/command/registry/warning.go b/cli/command/registry/warning.go new file mode 100644 index 0000000000..22a8c8655b --- /dev/null +++ b/cli/command/registry/warning.go @@ -0,0 +1,18 @@ +package registry + +import ( + "os" + + "github.com/docker/cli/cli/command" + "github.com/docker/cli/cli/config/configfile" + "github.com/docker/cli/internal/tui" +) + +// maybePrintEnvAuthWarning if the `DOCKER_AUTH_CONFIG` environment variable is +// set this function will output a warning to stdErr +func maybePrintEnvAuthWarning(out command.Streams) { + if os.Getenv(configfile.DockerEnvConfigKey) != "" { + tui.NewOutput(out.Err()). + PrintWarning("%[1]s is set and takes precedence.\nUnset %[1]s to restore the CLI auth behaviour.\n", configfile.DockerEnvConfigKey) + } +}