info.go 4.6 KB

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