info.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package client
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/pkg/ioutils"
  7. flag "github.com/docker/docker/pkg/mflag"
  8. "github.com/docker/docker/pkg/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, "Display system-wide information", true)
  15. cmd.Require(flag.Exact, 0)
  16. cmd.ParseFlags(args, true)
  17. rdr, _, _, err := cli.call("GET", "/info", nil, nil)
  18. if err != nil {
  19. return err
  20. }
  21. defer rdr.Close()
  22. info := &types.Info{}
  23. if err := json.NewDecoder(rdr).Decode(info); err != nil {
  24. return fmt.Errorf("Error reading remote info: %v", err)
  25. }
  26. fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
  27. fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
  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. }
  33. }
  34. ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver)
  35. ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver)
  36. ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion)
  37. ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem)
  38. fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU)
  39. fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal)))
  40. ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
  41. ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
  42. if info.Debug {
  43. fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
  44. fmt.Fprintf(cli.out, "File Descriptors: %d\n", info.NFd)
  45. fmt.Fprintf(cli.out, "Goroutines: %d\n", info.NGoroutines)
  46. fmt.Fprintf(cli.out, "System Time: %s\n", info.SystemTime)
  47. fmt.Fprintf(cli.out, "EventsListeners: %d\n", info.NEventsListener)
  48. fmt.Fprintf(cli.out, "Init SHA1: %s\n", info.InitSha1)
  49. fmt.Fprintf(cli.out, "Init Path: %s\n", info.InitPath)
  50. fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir)
  51. }
  52. ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HttpProxy)
  53. ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HttpsProxy)
  54. ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy)
  55. if info.IndexServerAddress != "" {
  56. u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username
  57. if len(u) > 0 {
  58. fmt.Fprintf(cli.out, "Username: %v\n", u)
  59. fmt.Fprintf(cli.out, "Registry: %v\n", info.IndexServerAddress)
  60. }
  61. }
  62. if !info.MemoryLimit {
  63. fmt.Fprintf(cli.err, "WARNING: No memory limit support\n")
  64. }
  65. if !info.SwapLimit {
  66. fmt.Fprintf(cli.err, "WARNING: No swap limit support\n")
  67. }
  68. if !info.IPv4Forwarding {
  69. fmt.Fprintf(cli.err, "WARNING: IPv4 forwarding is disabled.\n")
  70. }
  71. if !info.BridgeNfIptables {
  72. fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-iptables is disabled\n")
  73. }
  74. if !info.BridgeNfIp6tables {
  75. fmt.Fprintf(cli.err, "WARNING: bridge-nf-call-ip6tables is disabled\n")
  76. }
  77. if info.Labels != nil {
  78. fmt.Fprintln(cli.out, "Labels:")
  79. for _, attribute := range info.Labels {
  80. fmt.Fprintf(cli.out, " %s\n", attribute)
  81. }
  82. }
  83. if info.ExperimentalBuild {
  84. fmt.Fprintf(cli.out, "Experimental: true\n")
  85. }
  86. return nil
  87. }