2014-07-01 21:52:59 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-08-17 11:35:34 -04:00
|
|
|
"encoding/json"
|
2015-03-26 15:43:00 -04:00
|
|
|
"fmt"
|
2014-07-01 21:52:59 -04:00
|
|
|
"os/exec"
|
2015-03-26 15:43:00 -04:00
|
|
|
"strconv"
|
2014-07-01 21:52:59 -04:00
|
|
|
"strings"
|
2015-07-26 09:00:53 -04:00
|
|
|
"time"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
2015-06-03 15:21:38 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-10-05 19:48:31 -04:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2015-08-17 11:35:34 -04:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-07-01 21:52:59 -04:00
|
|
|
)
|
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
func checkValidGraphDriver(c *check.C, name string) {
|
|
|
|
if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" {
|
|
|
|
c.Fatalf("%v is not a valid graph driver name", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestInspectImage(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-10-28 17:06:23 -04:00
|
|
|
imageTest := "emptyfs"
|
2014-10-06 10:26:55 -04:00
|
|
|
imageTestID := "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158"
|
2015-05-17 22:06:13 -04:00
|
|
|
id, err := inspectField(imageTest, "Id")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2014-10-14 16:06:06 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(id, checker.Equals, imageTestID)
|
2014-07-01 21:52:59 -04:00
|
|
|
}
|
2015-04-22 21:28:07 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectInt64(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-22 21:28:07 -04:00
|
|
|
|
2015-10-13 11:42:25 -04:00
|
|
|
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
|
|
|
|
inspectOut, err := inspectField("inspectTest", "HostConfig.Memory")
|
2015-05-17 22:06:13 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(inspectOut, checker.Equals, "314572800")
|
2015-04-22 21:28:07 -04:00
|
|
|
}
|
2015-03-26 15:43:00 -04:00
|
|
|
|
2015-06-26 10:47:31 -04:00
|
|
|
func (s *DockerSuite) TestInspectDefault(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 10:47:31 -04:00
|
|
|
//Both the container and image are named busybox. docker inspect will fetch the container JSON.
|
|
|
|
//If the container JSON is not available, it will go for the image JSON.
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
|
|
dockerCmd(c, "inspect", "busybox")
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2015-07-27 20:48:27 -04:00
|
|
|
func (s *DockerSuite) TestInspectStatus(c *check.C) {
|
2015-09-25 05:15:16 -04:00
|
|
|
defer unpauseAllContainers()
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-27 20:48:27 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
|
|
|
|
inspectOut, err := inspectField(out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
2015-07-27 20:48:27 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "pause", out)
|
|
|
|
inspectOut, err = inspectField(out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(inspectOut, checker.Equals, "paused")
|
2015-07-27 20:48:27 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "unpause", out)
|
|
|
|
inspectOut, err = inspectField(out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
2015-07-27 20:48:27 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "stop", out)
|
|
|
|
inspectOut, err = inspectField(out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(inspectOut, checker.Equals, "exited")
|
|
|
|
|
2015-07-27 20:48:27 -04:00
|
|
|
}
|
|
|
|
|
2015-06-26 10:47:31 -04:00
|
|
|
func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 10:47:31 -04:00
|
|
|
//Both the container and image are named busybox. docker inspect will fetch container
|
|
|
|
//JSON State.Running field. If the field is true, it's a container.
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
formatStr := "--format='{{.State.Running}}'"
|
2015-10-05 19:48:31 -04:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
|
|
|
c.Assert(out, checker.Equals, "true\n") // not a container JSON
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 10:47:31 -04:00
|
|
|
//Run this test on an image named busybox. docker inspect will try to fetch container
|
|
|
|
//JSON. Since there is no container named busybox and --type=container, docker inspect will
|
|
|
|
//not try to get the image JSON. It will throw an error.
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
_, _, err := dockerCmdWithError("inspect", "--type=container", "busybox")
|
|
|
|
// docker inspect should fail, as there is no container named busybox
|
|
|
|
c.Assert(err, checker.NotNil)
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 10:47:31 -04:00
|
|
|
//Both the container and image are named busybox. docker inspect will fetch image
|
|
|
|
//JSON as --type=image. if there is no image with name busybox, docker inspect
|
|
|
|
//will throw an error.
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 10:47:31 -04:00
|
|
|
//Both the container and image are named busybox. docker inspect will fail
|
|
|
|
//as --type=foobar is not a valid value for the flag.
|
|
|
|
|
2015-07-20 02:55:40 -04:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2015-07-27 14:13:25 -04:00
|
|
|
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.NotNil, check.Commentf("%s", exitCode))
|
|
|
|
c.Assert(exitCode, checker.Equals, 1, check.Commentf("%s", err))
|
|
|
|
c.Assert(out, checker.Contains, "not a valid value for --type")
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2015-03-26 15:43:00 -04:00
|
|
|
func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-03-26 15:43:00 -04:00
|
|
|
imageTest := "emptyfs"
|
2015-05-17 22:06:13 -04:00
|
|
|
out, err := inspectField(imageTest, "Size")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-17 22:06:13 -04:00
|
|
|
|
|
|
|
size, err := strconv.Atoi(out)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
|
2015-03-26 15:43:00 -04:00
|
|
|
|
|
|
|
//now see if the size turns out to be the same
|
|
|
|
formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size)
|
2015-10-05 19:48:31 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", formatStr, imageTest)
|
|
|
|
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(result, checker.Equals, true)
|
2015-03-26 15:43:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-16 14:04:25 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
|
|
|
|
runCmd.Stdin = strings.NewReader("blahblah")
|
2015-03-26 15:43:00 -04:00
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to run container: %v, output: %q", err, out))
|
2015-03-26 15:43:00 -04:00
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2015-05-17 22:06:13 -04:00
|
|
|
out, err = inspectField(id, "State.ExitCode")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-17 22:06:13 -04:00
|
|
|
|
|
|
|
exitCode, err := strconv.Atoi(out)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
|
2015-03-26 15:43:00 -04:00
|
|
|
|
|
|
|
//now get the exit code to verify
|
|
|
|
formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode)
|
2015-07-20 02:55:40 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
2015-10-05 19:48:31 -04:00
|
|
|
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(result, checker.Equals, true)
|
2015-03-26 15:43:00 -04:00
|
|
|
}
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-15 14:05:10 -04:00
|
|
|
imageTest := "emptyfs"
|
|
|
|
name, err := inspectField(imageTest, "GraphDriver.Name")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
checkValidGraphDriver(c, name)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
if name != "devicemapper" {
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Skip("requires devicemapper graphdriver")
|
2015-06-15 14:05:10 -04:00
|
|
|
}
|
|
|
|
|
2015-07-22 08:59:24 -04:00
|
|
|
deviceID, err := inspectField(imageTest, "GraphDriver.Data.DeviceId")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2015-07-22 08:59:24 -04:00
|
|
|
_, err = strconv.Atoi(deviceID)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
deviceSize, err := inspectField(imageTest, "GraphDriver.Data.DeviceSize")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
2015-06-15 14:05:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-20 02:55:40 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-06-15 14:05:10 -04:00
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
|
|
|
|
name, err := inspectField(out, "GraphDriver.Name")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
checkValidGraphDriver(c, name)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
if name != "devicemapper" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:59:24 -04:00
|
|
|
deviceID, err := inspectField(out, "GraphDriver.Data.DeviceId")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2015-07-22 08:59:24 -04:00
|
|
|
_, err = strconv.Atoi(deviceID)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
deviceSize, err := inspectField(out, "GraphDriver.Data.DeviceSize")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-15 14:05:10 -04:00
|
|
|
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
2015-06-15 14:05:10 -04:00
|
|
|
}
|
2015-06-03 15:21:38 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-03 15:21:38 -04:00
|
|
|
dockerCmd(c, "run", "-d", "--name", "test", "-v", "/data:/data:ro,z", "busybox", "cat")
|
|
|
|
|
|
|
|
vol, err := inspectFieldJSON("test", "Mounts")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-03 15:21:38 -04:00
|
|
|
|
|
|
|
var mp []types.MountPoint
|
|
|
|
err = unmarshalJSON([]byte(vol), &mp)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-03 15:21:38 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
// check that there is only one mountpoint
|
|
|
|
c.Assert(mp, check.HasLen, 1)
|
2015-06-03 15:21:38 -04:00
|
|
|
|
|
|
|
m := mp[0]
|
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(m.Name, checker.Equals, "")
|
|
|
|
c.Assert(m.Driver, checker.Equals, "")
|
|
|
|
c.Assert(m.Source, checker.Equals, "/data")
|
|
|
|
c.Assert(m.Destination, checker.Equals, "/data")
|
|
|
|
c.Assert(m.Mode, checker.Equals, "ro,z")
|
|
|
|
c.Assert(m.RW, checker.Equals, false)
|
2015-06-03 15:21:38 -04:00
|
|
|
}
|
2015-07-26 09:00:53 -04:00
|
|
|
|
|
|
|
// #14947
|
|
|
|
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-26 09:00:53 -04:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
startedAt, err := inspectField(id, "State.StartedAt")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
finishedAt, err := inspectField(id, "State.FinishedAt")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
created, err := inspectField(id, "Created")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
|
|
|
|
_, err = time.Parse(time.RFC3339Nano, startedAt)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, finishedAt)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
|
|
|
|
created, err = inspectField("busybox", "Created")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
|
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 09:00:53 -04:00
|
|
|
}
|
2015-08-17 11:35:34 -04:00
|
|
|
|
|
|
|
// #15633
|
|
|
|
func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) {
|
2015-08-28 13:36:42 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-08-17 11:35:34 -04:00
|
|
|
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
|
|
|
|
var logConfig runconfig.LogConfig
|
|
|
|
|
|
|
|
out, err := inspectFieldJSON("test", "HostConfig.LogConfig")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
|
2015-08-17 11:35:34 -04:00
|
|
|
|
|
|
|
err = json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
|
2015-08-17 11:35:34 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(logConfig.Type, checker.Equals, "json-file")
|
|
|
|
c.Assert(logConfig.Config["max-file"], checker.Equals, "42", check.Commentf("%v", logConfig))
|
2015-08-17 11:35:34 -04:00
|
|
|
}
|
2015-09-25 08:49:02 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) {
|
|
|
|
|
|
|
|
//Both the container and image are named busybox. docker inspect will fetch container
|
|
|
|
//JSON SizeRw and SizeRootFs field. If there is no flag --size/-s, there are no size fields.
|
|
|
|
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
2015-09-25 08:49:02 -04:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Exepcted not to display size info: %s", out))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
2015-09-25 08:49:02 -04:00
|
|
|
out, _ := dockerCmd(c, "inspect", "-s", "--type=container", formatStr, "busybox")
|
|
|
|
sz := strings.Split(out, ",")
|
|
|
|
|
|
|
|
c.Assert(strings.TrimSpace(sz[0]), check.Not(check.Equals), "<nil>")
|
|
|
|
c.Assert(strings.TrimSpace(sz[1]), check.Not(check.Equals), "<nil>")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectSizeFlagImage(c *check.C) {
|
2015-10-22 18:42:19 -04:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "-s", "--type=image", formatStr, "busybox")
|
|
|
|
|
|
|
|
// Template error rather than <no value>
|
|
|
|
// This is a more correct behavior because images don't have sizes associated.
|
|
|
|
c.Assert(err, check.Not(check.IsNil))
|
|
|
|
c.Assert(out, checker.Contains, "Template parsing error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTempateError(c *check.C) {
|
|
|
|
//Both the container and image are named busybox. docker inspect will fetch container
|
|
|
|
//JSON State.Running field. If the field is true, it's a container.
|
2015-09-25 08:49:02 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2015-10-22 18:42:19 -04:00
|
|
|
c.Assert(err, check.Not(check.IsNil))
|
|
|
|
c.Assert(out, checker.Contains, "Template parsing error")
|
2015-09-25 08:49:02 -04:00
|
|
|
}
|
2015-11-06 17:22:48 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
|
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.HostConfig.Dns}}'", "busybox")
|
|
|
|
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "[]\n")
|
|
|
|
}
|