github.com/campoy/docker@v1.8.0-rc1/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, "Display system-wide information", 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, "Storage Driver: %s\n", info.Driver) 39 if info.DriverStatus != nil { 40 for _, pair := range info.DriverStatus { 41 fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1]) 42 } 43 } 44 ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver) 45 ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver) 46 ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion) 47 ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem) 48 fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU) 49 fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) 50 ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name) 51 ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID) 52 53 if info.Debug { 54 fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug) 55 fmt.Fprintf(cli.out, "File Descriptors: %d\n", info.NFd) 56 fmt.Fprintf(cli.out, "Goroutines: %d\n", info.NGoroutines) 57 fmt.Fprintf(cli.out, "System Time: %s\n", info.SystemTime) 58 fmt.Fprintf(cli.out, "EventsListeners: %d\n", info.NEventsListener) 59 fmt.Fprintf(cli.out, "Init SHA1: %s\n", info.InitSha1) 60 fmt.Fprintf(cli.out, "Init Path: %s\n", info.InitPath) 61 fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir) 62 } 63 64 ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HttpProxy) 65 ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HttpsProxy) 66 ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy) 67 68 if info.IndexServerAddress != "" { 69 u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username 70 if len(u) > 0 { 71 fmt.Fprintf(cli.out, "Username: %v\n", u) 72 fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress) 73 } 74 } 75 // Only output these warnings if the server supports these features 76 if h, err := httputils.ParseServerHeader(serverResp.header.Get("Server")); err == nil { 77 if h.OS != "windows" { 78 if !info.MemoryLimit { 79 fmt.Fprintf(cli.err, "WARNING: No memory limit support\n") 80 } 81 if !info.SwapLimit { 82 fmt.Fprintf(cli.err, "WARNING: No swap limit support\n") 83 } 84 if !info.IPv4Forwarding { 85 fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled.\n") 86 } 87 if !info.BridgeNfIptables { 88 fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n") 89 } 90 if !info.BridgeNfIp6tables { 91 fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n") 92 } 93 } 94 } 95 96 if info.Labels != nil { 97 fmt.Fprintln(cli.out, "Labels:") 98 for _, attribute := range info.Labels { 99 fmt.Fprintf(cli.out, " %s\n", attribute) 100 } 101 } 102 103 if info.ExperimentalBuild { 104 fmt.Fprintf(cli.out, "Experimental: true\n") 105 } 106 107 return nil 108 }