info.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package client
  2. import (
  3. "fmt"
  4. "strings"
  5. Cli "github.com/docker/docker/cli"
  6. "github.com/docker/docker/pkg/ioutils"
  7. flag "github.com/docker/docker/pkg/mflag"
  8. "github.com/docker/docker/utils"
  9. "github.com/docker/go-units"
  10. )
  11. // CmdInfo displays system-wide information.
  12. //
  13. // Usage: docker info
  14. func (cli *DockerCli) CmdInfo(args ...string) error {
  15. cmd := Cli.Subcmd("info", nil, Cli.DockerCommands["info"].Description, true)
  16. cmd.Require(flag.Exact, 0)
  17. cmd.ParseFlags(args, true)
  18. info, err := cli.client.Info()
  19. if err != nil {
  20. return err
  21. }
  22. fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
  23. fmt.Fprintf(cli.out, " Running: %d\n", info.ContainersRunning)
  24. fmt.Fprintf(cli.out, " Paused: %d\n", info.ContainersPaused)
  25. fmt.Fprintf(cli.out, " Stopped: %d\n", info.ContainersStopped)
  26. fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
  27. ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
  28. ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver)
  29. if info.DriverStatus != nil {
  30. for _, pair := range info.DriverStatus {
  31. fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
  32. // print a warning if devicemapper is using a loopback file
  33. if pair[0] == "Data loop file" {
  34. 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.")
  35. }
  36. }
  37. }
  38. if info.SystemStatus != nil {
  39. for _, pair := range info.SystemStatus {
  40. fmt.Fprintf(cli.out, "%s: %s\n", pair[0], pair[1])
  41. }
  42. }
  43. ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver)
  44. ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver)
  45. ioutils.FprintfIfNotEmpty(cli.out, "Cgroup Driver: %s\n", info.CgroupDriver)
  46. fmt.Fprintf(cli.out, "Plugins: \n")
  47. fmt.Fprintf(cli.out, " Volume:")
  48. fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Volume, " "))
  49. fmt.Fprintf(cli.out, "\n")
  50. fmt.Fprintf(cli.out, " Network:")
  51. fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Network, " "))
  52. fmt.Fprintf(cli.out, "\n")
  53. if len(info.Plugins.Authorization) != 0 {
  54. fmt.Fprintf(cli.out, " Authorization:")
  55. fmt.Fprintf(cli.out, " %s", strings.Join(info.Plugins.Authorization, " "))
  56. fmt.Fprintf(cli.out, "\n")
  57. }
  58. ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion)
  59. ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem)
  60. ioutils.FprintfIfNotEmpty(cli.out, "OSType: %s\n", info.OSType)
  61. ioutils.FprintfIfNotEmpty(cli.out, "Architecture: %s\n", info.Architecture)
  62. fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU)
  63. fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal)))
  64. ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
  65. ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
  66. fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir)
  67. fmt.Fprintf(cli.out, "Debug mode (client): %v\n", utils.IsDebugEnabled())
  68. fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
  69. if info.Debug {
  70. fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd)
  71. fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines)
  72. fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime)
  73. fmt.Fprintf(cli.out, " EventsListeners: %d\n", info.NEventsListener)
  74. }
  75. ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HTTPProxy)
  76. ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HTTPSProxy)
  77. ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy)
  78. if info.IndexServerAddress != "" {
  79. u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username
  80. if len(u) > 0 {
  81. fmt.Fprintf(cli.out, "Username: %v\n", u)
  82. fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress)
  83. }
  84. }
  85. // Only output these warnings if the server does not support these features
  86. if info.OSType != "windows" {
  87. if !info.MemoryLimit {
  88. fmt.Fprintln(cli.err, "WARNING: No memory limit support")
  89. }
  90. if !info.SwapLimit {
  91. fmt.Fprintln(cli.err, "WARNING: No swap limit support")
  92. }
  93. if !info.OomKillDisable {
  94. fmt.Fprintln(cli.err, "WARNING: No oom kill disable support")
  95. }
  96. if !info.CPUCfsQuota {
  97. fmt.Fprintln(cli.err, "WARNING: No cpu cfs quota support")
  98. }
  99. if !info.CPUCfsPeriod {
  100. fmt.Fprintln(cli.err, "WARNING: No cpu cfs period support")
  101. }
  102. if !info.CPUShares {
  103. fmt.Fprintln(cli.err, "WARNING: No cpu shares support")
  104. }
  105. if !info.CPUSet {
  106. fmt.Fprintln(cli.err, "WARNING: No cpuset support")
  107. }
  108. if !info.IPv4Forwarding {
  109. fmt.Fprintln(cli.err, "WARNING: IPv4 forwarding is disabled")
  110. }
  111. if !info.BridgeNfIptables {
  112. fmt.Fprintln(cli.err, "WARNING: bridge-nf-call-iptables is disabled")
  113. }
  114. if !info.BridgeNfIP6tables {
  115. fmt.Fprintln(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled")
  116. }
  117. }
  118. if info.Labels != nil {
  119. fmt.Fprintln(cli.out, "Labels:")
  120. for _, attribute := range info.Labels {
  121. fmt.Fprintf(cli.out, " %s\n", attribute)
  122. }
  123. }
  124. ioutils.FprintfIfTrue(cli.out, "Experimental: %v\n", info.ExperimentalBuild)
  125. if info.ClusterStore != "" {
  126. fmt.Fprintf(cli.out, "Cluster store: %s\n", info.ClusterStore)
  127. }
  128. if info.ClusterAdvertise != "" {
  129. fmt.Fprintf(cli.out, "Cluster advertise: %s\n", info.ClusterAdvertise)
  130. }
  131. return nil
  132. }