Skip to content

Commit

Permalink
Added additional container information to "docker info".
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit a9804ab1cb117a132cbf460067d55f5146d50956)
  • Loading branch information
netbrain authored and calavera committed Jan 12, 2016
1 parent 058e6dc commit e732f4e
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/client/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
}

fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers)
fmt.Fprintf(cli.out, " Running: %d\n", info.ContainersRunning)
fmt.Fprintf(cli.out, " Paused: %d\n", info.ContainersPaused)
fmt.Fprintf(cli.out, " Stopped: %d\n", info.ContainersStopped)
fmt.Fprintf(cli.out, "Images: %d\n", info.Images)
ioutils.FprintfIfNotEmpty(cli.out, "Server Version: %s\n", info.ServerVersion)
ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver)
Expand Down
15 changes: 15 additions & 0 deletions daemon/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,24 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
initPath := utils.DockerInitPath("")
sysInfo := sysinfo.New(true)

var cRunning, cPaused, cStopped int
for _, c := range daemon.List() {
switch c.StateString() {
case "paused":
cPaused++
case "running":
cRunning++
default:
cStopped++
}
}

v := &types.Info{
ID: daemon.ID,
Containers: len(daemon.List()),
ContainersRunning: cRunning,
ContainersPaused: cPaused,
ContainersStopped: cStopped,
Images: len(daemon.imageStore.Map()),
Driver: daemon.GraphDriverName(),
DriverStatus: daemon.layerStore.DriverStatus(),
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/commandline/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ For example:

$ docker -D info
Containers: 14
Running: 3
Paused: 1
Stopped: 10
Images: 52
Server Version: 1.9.0
Storage Driver: aufs
Expand Down
3 changes: 3 additions & 0 deletions docs/userguide/labels-custom-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ These labels appear as part of the `docker info` output for the daemon:

$ docker -D info
Containers: 12
Running: 5
Paused: 2
Stopped: 5
Images: 672
Server Version: 1.9.0
Storage Driver: aufs
Expand Down
1 change: 1 addition & 0 deletions integration-cli/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type DockerSuite struct {
}

func (s *DockerSuite) TearDownTest(c *check.C) {
unpauseAllContainers()
deleteAllContainers()
deleteAllImages()
deleteAllVolumes()
Expand Down
3 changes: 3 additions & 0 deletions integration-cli/docker_api_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func (s *DockerSuite) TestInfoApi(c *check.C) {
stringsToCheck := []string{
"ID",
"Containers",
"ContainersRunning",
"ContainersPaused",
"ContainersStopped",
"Images",
"ExecutionDriver",
"LoggingDriver",
Expand Down
45 changes: 45 additions & 0 deletions integration-cli/docker_cli_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net"
"strings"

"github.com/docker/docker/pkg/integration/checker"
"github.com/docker/docker/utils"
Expand All @@ -17,6 +18,9 @@ func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
stringsToCheck := []string{
"ID:",
"Containers:",
" Running:",
" Paused:",
" Stopped:",
"Images:",
"Execution Driver:",
"OSType:",
Expand Down Expand Up @@ -101,3 +105,44 @@ func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s:2375\n", ip.String()))
}

func (s *DockerSuite) TestInfoDisplaysRunningContainers(c *check.C) {
testRequires(c, DaemonIsLinux)

dockerCmd(c, "run", "-d", "busybox", "top")
out, _ := dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
}

func (s *DockerSuite) TestInfoDisplaysPausedContainers(c *check.C) {
testRequires(c, DaemonIsLinux)

out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)

dockerCmd(c, "pause", cleanedContainerID)

out, _ = dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 0))
}

func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
testRequires(c, DaemonIsLinux)

out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)

dockerCmd(c, "stop", cleanedContainerID)

out, _ = dockerCmd(c, "info")
c.Assert(out, checker.Contains, fmt.Sprintf("Containers: %d\n", 1))
c.Assert(out, checker.Contains, fmt.Sprintf(" Running: %d\n", 0))
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
}
3 changes: 3 additions & 0 deletions man/docker-info.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Here is a sample output:

# docker info
Containers: 14
Running: 3
Paused: 1
Stopped: 10
Images: 52
Server Version: 1.9.0
Storage Driver: aufs
Expand Down
3 changes: 3 additions & 0 deletions vendor/src/github.com/docker/engine-api/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ type Version struct {
type Info struct {
ID string
Containers int
ContainersRunning int
ContainersPaused int
ContainersStopped int
Images int
Driver string
DriverStatus [][2]string
Expand Down

0 comments on commit e732f4e

Please sign in to comment.