github.com/sijibomii/docker@v0.0.0-20231230191044-5cf6ca554647/api/client/info.go (about)

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