From a82e6868ccf58ded6650faf454df8d1408cba5b5 Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 28 Mar 2019 20:58:41 +0000 Subject: [PATCH] Use the default registry even without --debug Previously if the Docker engine was not running the behaviour of commands would vary depending on whether the --debug flag was provided. For example, consider `docker logout`: $ docker logout Not logged in to -- note the missing server URL $ docker --debug logout Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/ Not logged in to https://index.docker.io/v1/ -- note the server URL is present This patch makes only the debug printing conditional on the `--debug` flag, not the return value. Signed-off-by: David Scott --- cli/command/registry.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index c86edcc79f..90189b9482 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -29,11 +29,16 @@ func ElectAuthServer(ctx context.Context, cli Cli) string { // example a Linux client might be interacting with a Windows daemon, hence // the default registry URL might be Windows specific. serverAddress := registry.IndexServer - if info, err := cli.Client().Info(ctx); err != nil && debug.IsEnabled() { - // Only report the warning if we're in debug mode to prevent nagging during engine initialization workflows - fmt.Fprintf(cli.Err(), "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress) - } else if info.IndexServerAddress == "" && debug.IsEnabled() { - fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", serverAddress) + if info, err := cli.Client().Info(ctx); err != nil { + // Daemon is not responding so use system default. + if debug.IsEnabled() { + // Only report the warning if we're in debug mode to prevent nagging during engine initialization workflows + fmt.Fprintf(cli.Err(), "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress) + } + } else if info.IndexServerAddress == "" { + if debug.IsEnabled() { + fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", serverAddress) + } } else { serverAddress = info.IndexServerAddress }