github.com/uriddle/docker@v0.0.0-20210926094723-4072e6aeb013/api/client/info.go (about)

     1  package client
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	Cli "github.com/docker/docker/cli"
     8  	"github.com/docker/docker/pkg/ioutils"
     9  	flag "github.com/docker/docker/pkg/mflag"
    10  	"github.com/docker/go-units"
    11  )
    12  
    13  // CmdInfo displays system-wide information.
    14  //
    15  // Usage: docker info
    16  func (cli *DockerCli) CmdInfo(args ...string) error {
    17  	cmd := Cli.Subcmd("info", nil, Cli.DockerCommands["info"].Description, true)
    18  	cmd.Require(flag.Exact, 0)
    19  
    20  	cmd.ParseFlags(args, true)
    21  
    22  	info, err := cli.client.Info()
    23  	if err != nil {
    24  		return err
    25  	}
    26  
    27  	fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
    28  	fmt.Fprintf(cli.out, " Running: %d\n", info.ContainersRunning)
    29  	fmt.Fprintf(cli.out, " Paused: %d\n", info.ContainersPaused)
    30  	fmt.Fprintf(cli.out, " Stopped: %d\n", info.ContainersStopped)
    31  	fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
    32  	ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
    33  	ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver)
    34  	if info.DriverStatus != nil {
    35  		for _, pair := range info.DriverStatus {
    36  			fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
    37  
    38  			// print a warning if devicemapper is using a loopback file
    39  			if pair[0] == "Data loop file" {
    40  				fmt.Fprintln(cli.err, " WARNING: Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.")
    41  			}
    42  		}
    43  
    44  	}
    45  	if info.SystemStatus != nil {
    46  		for _, pair := range info.SystemStatus {
    47  			fmt.Fprintf(cli.out, "%s: %s\n", pair[0], pair[1])
    48  		}
    49  	}
    50  	ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver)
    51  	ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver)
    52  
    53  	fmt.Fprintf(cli.out, "Plugins: \n")
    54  	fmt.Fprintf(cli.out, " Volume:")
    55  	fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Volume, " "))
    56  	fmt.Fprintf(cli.out, "\n")
    57  	fmt.Fprintf(cli.out, " Network:")
    58  	fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Network, " "))
    59  	fmt.Fprintf(cli.out, "\n")
    60  
    61  	if len(info.Plugins.Authorization) != 0 {
    62  		fmt.Fprintf(cli.out, " Authorization:")
    63  		fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Authorization, " "))
    64  		fmt.Fprintf(cli.out, "\n")
    65  	}
    66  
    67  	ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion)
    68  	ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem)
    69  	ioutils.FprintfIfNotEmpty(cli.out, "OSType: %s\n", info.OSType)
    70  	ioutils.FprintfIfNotEmpty(cli.out, "Architecture: %s\n", info.Architecture)
    71  	fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU)
    72  	fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal)))
    73  	ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
    74  	ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
    75  
    76  	if info.Debug {
    77  		fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
    78  		fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd)
    79  		fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines)
    80  		fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime)
    81  		fmt.Fprintf(cli.out, " EventsListeners: %d\n", info.NEventsListener)
    82  		fmt.Fprintf(cli.out, " Init SHA1: %s\n", info.InitSha1)
    83  		fmt.Fprintf(cli.out, " Init Path: %s\n", info.InitPath)
    84  		fmt.Fprintf(cli.out, " Docker Root Dir: %s\n", info.DockerRootDir)
    85  	}
    86  
    87  	ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HTTPProxy)
    88  	ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HTTPSProxy)
    89  	ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy)
    90  
    91  	if info.IndexServerAddress != "" {
    92  		u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username
    93  		if len(u) > 0 {
    94  			fmt.Fprintf(cli.out, "Username: %v\n", u)
    95  			fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress)
    96  		}
    97  	}
    98  
    99  	// Only output these warnings if the server does not support these features
   100  	if info.OSType != "windows" {
   101  		if !info.MemoryLimit {
   102  			fmt.Fprintln(cli.err, "WARNING: No memory limit support")
   103  		}
   104  		if !info.SwapLimit {
   105  			fmt.Fprintln(cli.err, "WARNING: No swap limit support")
   106  		}
   107  		if !info.OomKillDisable {
   108  			fmt.Fprintln(cli.err, "WARNING: No oom kill disable support")
   109  		}
   110  		if !info.CPUCfsQuota {
   111  			fmt.Fprintln(cli.err, "WARNING: No cpu cfs quota support")
   112  		}
   113  		if !info.CPUCfsPeriod {
   114  			fmt.Fprintln(cli.err, "WARNING: No cpu cfs period support")
   115  		}
   116  		if !info.CPUShares {
   117  			fmt.Fprintln(cli.err, "WARNING: No cpu shares support")
   118  		}
   119  		if !info.CPUSet {
   120  			fmt.Fprintln(cli.err, "WARNING: No cpuset support")
   121  		}
   122  		if !info.IPv4Forwarding {
   123  			fmt.Fprintln(cli.err, "WARNING: IPv4 forwarding is disabled")
   124  		}
   125  		if !info.BridgeNfIptables {
   126  			fmt.Fprintln(cli.err, "WARNING: bridge-nf-call-iptables is disabled")
   127  		}
   128  		if !info.BridgeNfIP6tables {
   129  			fmt.Fprintln(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled")
   130  		}
   131  	}
   132  
   133  	if info.Labels != nil {
   134  		fmt.Fprintln(cli.out, "Labels:")
   135  		for _, attribute := range info.Labels {
   136  			fmt.Fprintf(cli.out, " %s\n", attribute)
   137  		}
   138  	}
   139  
   140  	ioutils.FprintfIfTrue(cli.out, "Experimental: %v\n", info.ExperimentalBuild)
   141  	if info.ClusterStore != "" {
   142  		fmt.Fprintf(cli.out, "Cluster store: %s\n", info.ClusterStore)
   143  	}
   144  
   145  	if info.ClusterAdvertise != "" {
   146  		fmt.Fprintf(cli.out, "Cluster advertise: %s\n", info.ClusterAdvertise)
   147  	}
   148  	return nil
   149  }