info.go 5.0 KB

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