@@ -416,14 +416,21 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
416416func areSubcommandsSupported (cmd * cobra.Command , details versionDetails ) error {
417417 // Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
418418 for curr := cmd ; curr != nil ; curr = curr .Parent () {
419+ // Important: in the code below, calls to "details.CurrentVersion()" and
420+ // "details.ServerInfo()" are deliberately executed inline to make them
421+ // be executed "lazily". This is to prevent making a connection with the
422+ // daemon to perform a "ping" (even for commands that do not require a
423+ // daemon connection).
424+ //
425+ // See commit b39739123b845f872549e91be184cc583f5b387c for details.
426+
419427 if cmdVersion , ok := curr .Annotations ["version" ]; ok && versions .LessThan (details .CurrentVersion (), cmdVersion ) {
420428 return fmt .Errorf ("%s requires API version %s, but the Docker daemon API version is %s" , cmd .CommandPath (), cmdVersion , details .CurrentVersion ())
421429 }
422- si := details .ServerInfo ()
423- if ost , ok := curr .Annotations ["ostype" ]; ok && si .OSType != "" && ost != si .OSType {
424- return fmt .Errorf ("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s" , cmd .CommandPath (), ost , si .OSType )
430+ if ost , ok := curr .Annotations ["ostype" ]; ok && details .ServerInfo ().OSType != "" && ost != details .ServerInfo ().OSType {
431+ return fmt .Errorf ("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s" , cmd .CommandPath (), ost , details .ServerInfo ().OSType )
425432 }
426- if _ , ok := curr .Annotations ["experimental" ]; ok && ! si .HasExperimental {
433+ if _ , ok := curr .Annotations ["experimental" ]; ok && ! details . ServerInfo () .HasExperimental {
427434 return fmt .Errorf ("%s is only supported on a Docker daemon with experimental features enabled" , cmd .CommandPath ())
428435 }
429436 }
0 commit comments