Instead of just showing the number of containers this patch will
show the number of running, paused and stopped containers as well.
Signed-off-by: Kim Eik <kim@heldig.org>
(cherry picked from commit a9804ab1cb117a132cbf460067d55f5146d50956)
| ... | ... |
@@ -25,6 +25,9 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 | 27 |
fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers) |
| 28 |
+ fmt.Fprintf(cli.out, " Running: %d\n", info.ContainersRunning) |
|
| 29 |
+ fmt.Fprintf(cli.out, " Paused: %d\n", info.ContainersPaused) |
|
| 30 |
+ fmt.Fprintf(cli.out, " Stopped: %d\n", info.ContainersStopped) |
|
| 28 | 31 |
fmt.Fprintf(cli.out, "Images: %d\n", info.Images) |
| 29 | 32 |
ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion) |
| 30 | 33 |
ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver) |
| ... | ... |
@@ -54,9 +54,24 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
| 54 | 54 |
initPath := utils.DockerInitPath("")
|
| 55 | 55 |
sysInfo := sysinfo.New(true) |
| 56 | 56 |
|
| 57 |
+ var cRunning, cPaused, cStopped int |
|
| 58 |
+ for _, c := range daemon.List() {
|
|
| 59 |
+ switch c.StateString() {
|
|
| 60 |
+ case "paused": |
|
| 61 |
+ cPaused++ |
|
| 62 |
+ case "running": |
|
| 63 |
+ cRunning++ |
|
| 64 |
+ default: |
|
| 65 |
+ cStopped++ |
|
| 66 |
+ } |
|
| 67 |
+ } |
|
| 68 |
+ |
|
| 57 | 69 |
v := &types.Info{
|
| 58 | 70 |
ID: daemon.ID, |
| 59 | 71 |
Containers: len(daemon.List()), |
| 72 |
+ ContainersRunning: cRunning, |
|
| 73 |
+ ContainersPaused: cPaused, |
|
| 74 |
+ ContainersStopped: cStopped, |
|
| 60 | 75 |
Images: len(daemon.imageStore.Map()), |
| 61 | 76 |
Driver: daemon.GraphDriverName(), |
| 62 | 77 |
DriverStatus: daemon.layerStore.DriverStatus(), |
| ... | ... |
@@ -3,6 +3,7 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"net" |
| 6 |
+ "strings" |
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/docker/docker/pkg/integration/checker" |
| 8 | 9 |
"github.com/docker/docker/utils" |
| ... | ... |
@@ -17,6 +18,9 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
|
| 17 | 17 |
stringsToCheck := []string{
|
| 18 | 18 |
"ID:", |
| 19 | 19 |
"Containers:", |
| 20 |
+ " Running:", |
|
| 21 |
+ " Paused:", |
|
| 22 |
+ " Stopped:", |
|
| 20 | 23 |
"Images:", |
| 21 | 24 |
"Execution Driver:", |
| 22 | 25 |
"OSType:", |
| ... | ... |
@@ -101,3 +105,44 @@ func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
|
| 101 | 101 |
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
|
| 102 | 102 |
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s:2375\n", ip.String()))
|
| 103 | 103 |
} |
| 104 |
+ |
|
| 105 |
+func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
|
|
| 106 |
+ testRequires(c, DaemonIsLinux) |
|
| 107 |
+ |
|
| 108 |
+ dockerCmd(c, "run", "-d", "busybox", "top") |
|
| 109 |
+ out, _ := dockerCmd(c, "info") |
|
| 110 |
+ c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
| 111 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1))
|
|
| 112 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
|
| 113 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
|
|
| 114 |
+} |
|
| 115 |
+ |
|
| 116 |
+func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
|
|
| 117 |
+ testRequires(c, DaemonIsLinux) |
|
| 118 |
+ |
|
| 119 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "top") |
|
| 120 |
+ cleanedContainerID := strings.TrimSpace(out) |
|
| 121 |
+ |
|
| 122 |
+ dockerCmd(c, "pause", cleanedContainerID) |
|
| 123 |
+ |
|
| 124 |
+ out, _ = dockerCmd(c, "info") |
|
| 125 |
+ c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
| 126 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
|
|
| 127 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1))
|
|
| 128 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
|
|
| 129 |
+} |
|
| 130 |
+ |
|
| 131 |
+func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
|
| 132 |
+ testRequires(c, DaemonIsLinux) |
|
| 133 |
+ |
|
| 134 |
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "top") |
|
| 135 |
+ cleanedContainerID := strings.TrimSpace(out) |
|
| 136 |
+ |
|
| 137 |
+ dockerCmd(c, "stop", cleanedContainerID) |
|
| 138 |
+ |
|
| 139 |
+ out, _ = dockerCmd(c, "info") |
|
| 140 |
+ c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
|
|
| 141 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
|
|
| 142 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
|
| 143 |
+ c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
|
|
| 144 |
+} |