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