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