diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index 673b78f88993..fa23a8abf06b 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -108,6 +108,9 @@ var acceptedStatsFilters = map[string]bool{ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) error { apiClient := dockerCLI.Client() + // Get the daemonOSType to handle platform-specific stats fields. + daemonOSType = dockerCLI.ServerInfo().OSType + // waitFirst is a WaitGroup to wait first stat data's reach for each container waitFirst := &sync.WaitGroup{} // closeChan is a non-buffered channel used to collect errors from goroutines. @@ -261,12 +264,6 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) format = formatter.TableFormatKey } } - if daemonOSType == "" { - // Get the daemonOSType if not set already. The daemonOSType variable - // should already be set when collecting stats as part of "collect()", - // so we unlikely hit this code in practice. - daemonOSType = dockerCLI.ServerInfo().OSType - } // Buffer to store formatted stats text. // Once formatted, it will be printed in one write to avoid screen flickering. diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index e80bcb97bfc3..8883752da9e7 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -95,8 +95,6 @@ func collect(ctx context.Context, s *Stats, cli client.ContainerAPIClient, strea continue } - daemonOSType = response.OSType - if daemonOSType != "windows" { previousCPU = v.PreCPUStats.CPUUsage.TotalUsage previousSystem = v.PreCPUStats.SystemUsage