github.com/a4a881d4/docker@v1.9.0-rc2/api/client/info.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/docker/docker/api/types" 8 Cli "github.com/docker/docker/cli" 9 "github.com/docker/docker/pkg/httputils" 10 "github.com/docker/docker/pkg/ioutils" 11 flag "github.com/docker/docker/pkg/mflag" 12 "github.com/docker/docker/pkg/units" 13 ) 14 15 // CmdInfo displays system-wide information. 16 // 17 // Usage: docker info 18 func (cli *DockerCli) CmdInfo(args ...string) error { 19 cmd := Cli.Subcmd("info", nil, Cli.DockerCommands["info"].Description, true) 20 cmd.Require(flag.Exact, 0) 21 22 cmd.ParseFlags(args, true) 23 24 serverResp, err := cli.call("GET", "/info", nil, nil) 25 if err != nil { 26 return err 27 } 28 29 defer serverResp.body.Close() 30 31 info := &types.Info{} 32 if err := json.NewDecoder(serverResp.body).Decode(info); err != nil { 33 return fmt.Errorf("Error reading remote info: %v", err) 34 } 35 36 fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers) 37 fmt.Fprintf(cli.out, "Images: %d\n", info.Images) 38 ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion) 39 ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver) 40 if info.DriverStatus != nil { 41 for _, pair := range info.DriverStatus { 42 fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1]) 43 } 44 } 45 ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver) 46 ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver) 47 ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion) 48 ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem) 49 fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU) 50 fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) 51 ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name) 52 ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID) 53 54 if info.Debug { 55 fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug) 56 fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd) 57 fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines) 58 fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime) 59 fmt.Fprintf(cli.out, " EventsListeners: %d\n", info.NEventsListener) 60 fmt.Fprintf(cli.out, " Init SHA1: %s\n", info.InitSha1) 61 fmt.Fprintf(cli.out, " Init Path: %s\n", info.InitPath) 62 fmt.Fprintf(cli.out, " Docker Root Dir: %s\n", info.DockerRootDir) 63 } 64 65 ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HTTPProxy) 66 ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HTTPSProxy) 67 ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy) 68 69 if info.IndexServerAddress != "" { 70 u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username 71 if len(u) > 0 { 72 fmt.Fprintf(cli.out, "Username: %v\n", u) 73 fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress) 74 } 75 } 76 77 // Only output these warnings if the server does not support these features 78 if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil { 79 if h.OS != "windows" { 80 if !info.MemoryLimit { 81 fmt.Fprintf(cli.err, "WARNING: No memory limit support\n") 82 } 83 if !info.SwapLimit { 84 fmt.Fprintf(cli.err, "WARNING: No swap limit support\n") 85 } 86 if !info.IPv4Forwarding { 87 fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled\n") 88 } 89 if !info.BridgeNfIptables { 90 fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n") 91 } 92 if !info.BridgeNfIP6tables { 93 fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n") 94 } 95 } 96 } 97 98 if info.Labels != nil { 99 fmt.Fprintln(cli.out, "Labels:") 100 for _, attribute := range info.Labels { 101 fmt.Fprintf(cli.out, " %s\n", attribute) 102 } 103 } 104 105 ioutils.FprintfIfTrue(cli.out, "Experimental: %v\n", info.ExperimentalBuild) 106 if info.ClusterStore != "" { 107 fmt.Fprintf(cli.out, "Cluster store: %s\n", info.ClusterStore) 108 } 109 110 return nil 111 }