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