2014-07-02 01:52:59 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-08-17 15:35:34 +00:00
|
|
|
"encoding/json"
|
2015-03-26 19:43:00 +00:00
|
|
|
"fmt"
|
2016-05-25 20:56:36 +00:00
|
|
|
"os"
|
2014-07-02 01:52:59 +00:00
|
|
|
"os/exec"
|
2015-03-26 19:43:00 +00:00
|
|
|
"strconv"
|
2014-07-02 01:52:59 +00:00
|
|
|
"strings"
|
2015-07-26 13:00:53 +00:00
|
|
|
"time"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2016-01-05 00:05:26 +00:00
|
|
|
"github.com/docker/engine-api/types"
|
|
|
|
"github.com/docker/engine-api/types/container"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-07-02 01:52:59 +00:00
|
|
|
)
|
|
|
|
|
2015-10-05 23:48:31 +00: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 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestInspectImage(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2014-10-28 21:06:23 +00:00
|
|
|
imageTest := "emptyfs"
|
2015-11-18 22:20:54 +00:00
|
|
|
// It is important that this ID remain stable. If a code change causes
|
|
|
|
// it to be different, this is equivalent to a cache bust when pulling
|
|
|
|
// a legacy-format manifest. If the check at the end of this function
|
|
|
|
// fails, fix the difference in the image serialization instead of
|
|
|
|
// updating this hash.
|
|
|
|
imageTestID := "sha256:11f64303f0f7ffdc71f001788132bca5346831939a956e3e975c93267d89a16d"
|
2016-01-28 14:19:25 +00:00
|
|
|
id := inspectField(c, imageTest, "Id")
|
2014-10-14 20:06:06 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(id, checker.Equals, imageTestID)
|
2014-07-02 01:52:59 +00:00
|
|
|
}
|
2015-04-23 01:28:07 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectInt64(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-04-23 01:28:07 +00:00
|
|
|
|
2015-10-13 15:42:25 +00:00
|
|
|
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(inspectOut, checker.Equals, "314572800")
|
2015-04-23 01:28:07 +00:00
|
|
|
}
|
2015-03-26 19:43:00 +00:00
|
|
|
|
2015-06-26 14:47:31 +00:00
|
|
|
func (s *DockerSuite) TestInspectDefault(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 14:47:31 +00: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-12-28 08:29:39 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut := inspectField(c, "busybox", "Id")
|
2015-12-28 08:29:39 +00:00
|
|
|
c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID)
|
2015-06-26 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 00:48:27 +00:00
|
|
|
func (s *DockerSuite) TestInspectStatus(c *check.C) {
|
2015-09-25 09:15:16 +00:00
|
|
|
defer unpauseAllContainers()
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-28 00:48:27 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "top")
|
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut := inspectField(c, out, "State.Status")
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
2015-07-28 00:48:27 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "pause", out)
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(inspectOut, checker.Equals, "paused")
|
2015-07-28 00:48:27 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "unpause", out)
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
2015-07-28 00:48:27 +00:00
|
|
|
|
|
|
|
dockerCmd(c, "stop", out)
|
2016-01-28 14:19:25 +00:00
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(inspectOut, checker.Equals, "exited")
|
|
|
|
|
2015-07-28 00:48:27 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 14:47:31 +00:00
|
|
|
func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 14:47:31 +00: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 06:55:40 +00:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top")
|
2015-06-26 14:47:31 +00:00
|
|
|
|
2015-10-22 22:42:19 +00:00
|
|
|
formatStr := "--format='{{.State.Running}}'"
|
2015-10-05 23:48:31 +00:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
|
|
|
c.Assert(out, checker.Equals, "true\n") // not a container JSON
|
2015-06-26 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithNoContainer(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 14:47:31 +00: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 06:55:40 +00:00
|
|
|
dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-06-26 14:47:31 +00:00
|
|
|
|
2015-10-05 23:48:31 +00: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 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithImage(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 14:47:31 +00: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 06:55:40 +00:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
2015-06-26 14:47:31 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=image", "busybox")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "State") // not an image JSON
|
2015-06-26 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectTypeFlagWithInvalidValue(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-06-26 14:47:31 +00: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 06:55:40 +00:00
|
|
|
dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
2015-06-26 14:47:31 +00:00
|
|
|
|
2015-07-27 18:13:25 +00:00
|
|
|
out, exitCode, err := dockerCmdWithError("inspect", "--type=foobar", "busybox")
|
2015-10-05 23:48:31 +00: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 14:47:31 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 19:43:00 +00:00
|
|
|
func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-03-26 19:43:00 +00:00
|
|
|
imageTest := "emptyfs"
|
2016-01-28 14:19:25 +00:00
|
|
|
out := inspectField(c, imageTest, "Size")
|
2015-05-18 02:06:13 +00:00
|
|
|
|
|
|
|
size, err := strconv.Atoi(out)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err))
|
2015-03-26 19:43:00 +00:00
|
|
|
|
|
|
|
//now see if the size turns out to be the same
|
|
|
|
formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size)
|
2015-10-05 23:48:31 +00: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 19:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-05-16 18:04:25 +00:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat")
|
|
|
|
runCmd.Stdin = strings.NewReader("blahblah")
|
2015-03-26 19:43:00 +00:00
|
|
|
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to run container: %v, output: %q", err, out))
|
2015-03-26 19:43:00 +00:00
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
out = inspectField(c, id, "State.ExitCode")
|
2015-05-18 02:06:13 +00:00
|
|
|
|
|
|
|
exitCode, err := strconv.Atoi(out)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err))
|
2015-03-26 19:43:00 +00:00
|
|
|
|
|
|
|
//now get the exit code to verify
|
|
|
|
formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode)
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
2015-10-05 23:48:31 +00:00
|
|
|
result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(result, checker.Equals, true)
|
2015-03-26 19:43:00 +00:00
|
|
|
}
|
2015-06-15 18:05:10 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectImageGraphDriver(c *check.C) {
|
2016-02-17 17:18:18 +00:00
|
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
2015-06-15 18:05:10 +00:00
|
|
|
imageTest := "emptyfs"
|
2016-01-28 14:19:25 +00:00
|
|
|
name := inspectField(c, imageTest, "GraphDriver.Name")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
checkValidGraphDriver(c, name)
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
_, err := strconv.Atoi(deviceID)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
2015-06-15 18:05:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerGraphDriver(c *check.C) {
|
2016-02-17 17:18:18 +00:00
|
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
|
|
|
|
2015-07-20 06:55:40 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
2015-06-15 18:05:10 +00:00
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
name := inspectField(c, out, "GraphDriver.Name")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
checkValidGraphDriver(c, name)
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
imageDeviceID := inspectField(c, "busybox", "GraphDriver.Data.DeviceId")
|
2015-12-15 00:52:15 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2015-12-15 00:52:15 +00:00
|
|
|
c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
_, err := strconv.Atoi(deviceID)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceId of the image: %s, %v", deviceID, err))
|
2015-06-15 18:05:10 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
|
2015-06-15 18:05:10 +00:00
|
|
|
|
|
|
|
_, err = strconv.ParseUint(deviceSize, 10, 64)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to inspect DeviceSize of the image: %s, %v", deviceSize, err))
|
2015-06-15 18:05:10 +00:00
|
|
|
}
|
2015-06-03 19:21:38 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
|
2016-05-25 20:56:36 +00:00
|
|
|
modifier := ",z"
|
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
|
|
|
if daemonPlatform == "windows" {
|
|
|
|
modifier = ""
|
|
|
|
// TODO Windows: Temporary check - remove once TP5 support is dropped
|
|
|
|
if windowsDaemonKV < 14350 {
|
|
|
|
c.Skip("Needs later Windows build for RO volumes")
|
|
|
|
}
|
|
|
|
// Linux creates the host directory if it doesn't exist. Windows does not.
|
|
|
|
os.Mkdir(`c:\data`, os.ModeDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "test", "-v", prefix+slash+"data:"+prefix+slash+"data:ro"+modifier, "busybox", "cat")
|
2015-06-03 19:21:38 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
vol := inspectFieldJSON(c, "test", "Mounts")
|
2015-06-03 19:21:38 +00:00
|
|
|
|
|
|
|
var mp []types.MountPoint
|
2016-01-28 14:19:25 +00:00
|
|
|
err := unmarshalJSON([]byte(vol), &mp)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-06-03 19:21:38 +00:00
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
// check that there is only one mountpoint
|
|
|
|
c.Assert(mp, check.HasLen, 1)
|
2015-06-03 19:21:38 +00:00
|
|
|
|
|
|
|
m := mp[0]
|
|
|
|
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(m.Name, checker.Equals, "")
|
|
|
|
c.Assert(m.Driver, checker.Equals, "")
|
2016-05-25 20:56:36 +00:00
|
|
|
c.Assert(m.Source, checker.Equals, prefix+slash+"data")
|
|
|
|
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
|
|
|
|
c.Assert(m.Mode, checker.Equals, "ro"+modifier)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(m.RW, checker.Equals, false)
|
2015-06-03 19:21:38 +00:00
|
|
|
}
|
2015-07-26 13:00:53 +00:00
|
|
|
|
|
|
|
// #14947
|
|
|
|
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-07-26 13:00:53 +00:00
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
id := strings.TrimSpace(out)
|
2016-01-28 14:19:25 +00:00
|
|
|
startedAt := inspectField(c, id, "State.StartedAt")
|
|
|
|
finishedAt := inspectField(c, id, "State.FinishedAt")
|
|
|
|
created := inspectField(c, id, "Created")
|
2015-07-26 13:00:53 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
_, err := time.Parse(time.RFC3339Nano, startedAt)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 13:00:53 +00:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, finishedAt)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 13:00:53 +00:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 13:00:53 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
created = inspectField(c, "busybox", "Created")
|
2015-07-26 13:00:53 +00:00
|
|
|
|
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil)
|
2015-07-26 13:00:53 +00:00
|
|
|
}
|
2015-08-17 15:35:34 +00:00
|
|
|
|
|
|
|
// #15633
|
|
|
|
func (s *DockerSuite) TestInspectLogConfigNoType(c *check.C) {
|
2015-08-28 17:36:42 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-08-17 15:35:34 +00:00
|
|
|
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
|
2015-12-18 18:36:17 +00:00
|
|
|
var logConfig container.LogConfig
|
2015-08-17 15:35:34 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
|
2015-08-17 15:35:34 +00:00
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
err := json.NewDecoder(strings.NewReader(out)).Decode(&logConfig)
|
2015-10-05 23:48:31 +00:00
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("%v", out))
|
2015-08-17 15:35:34 +00:00
|
|
|
|
2015-10-05 23:48:31 +00: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 15:35:34 +00:00
|
|
|
}
|
2015-09-25 12:49:02 +00: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.
|
|
|
|
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2015-10-22 22:42:19 +00:00
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
2015-09-25 12:49:02 +00: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) {
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2015-10-22 22:42:19 +00:00
|
|
|
formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'"
|
2015-09-25 12:49:02 +00: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) {
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "-d")
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2015-10-22 22:42:19 +00: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")
|
|
|
|
}
|
|
|
|
|
2016-02-24 18:17:25 +00:00
|
|
|
func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
|
2015-12-28 08:29:39 +00:00
|
|
|
// Template parsing error for both the container and image.
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "--name=container1", "-d")
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2015-12-28 08:29:39 +00:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='Format container: {{.ThisDoesNotExist}}'", "container1")
|
|
|
|
c.Assert(err, check.Not(check.IsNil))
|
|
|
|
c.Assert(out, checker.Contains, "Template parsing error")
|
2015-09-25 12:49:02 +00:00
|
|
|
|
2015-12-28 08:29:39 +00:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
2015-10-22 22:42:19 +00:00
|
|
|
c.Assert(err, check.Not(check.IsNil))
|
|
|
|
c.Assert(out, checker.Contains, "Template parsing error")
|
2015-09-25 12:49:02 +00:00
|
|
|
}
|
2015-11-06 22:22:48 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectJSONFields(c *check.C) {
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-11-06 22:22:48 +00:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.HostConfig.Dns}}'", "busybox")
|
|
|
|
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "[]\n")
|
|
|
|
}
|
2015-12-03 21:55:18 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
|
2016-01-28 14:19:25 +00:00
|
|
|
id := inspectField(c, "busybox", "Id")
|
2015-12-03 21:55:18 +00:00
|
|
|
c.Assert(id, checker.HasPrefix, "sha256:")
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
id2 := inspectField(c, id[:12], "Id")
|
2015-12-03 21:55:18 +00:00
|
|
|
c.Assert(id, checker.Equals, id2)
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
|
2015-12-03 21:55:18 +00:00
|
|
|
c.Assert(id, checker.Equals, id3)
|
|
|
|
}
|
2015-12-08 03:04:38 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
|
2016-02-24 18:17:25 +00:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
|
|
|
runSleepingContainer(c, "--name=not-shown", "-d")
|
2015-12-08 03:04:38 +00:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.Name}}'", "busybox", "missing", "not-shown")
|
|
|
|
|
|
|
|
c.Assert(err, checker.Not(check.IsNil))
|
|
|
|
c.Assert(out, checker.Contains, "busybox")
|
|
|
|
c.Assert(out, checker.Not(checker.Contains), "not-shown")
|
|
|
|
c.Assert(out, checker.Contains, "Error: No such container: missing")
|
|
|
|
}
|
2015-12-30 19:52:53 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectHistory(c *check.C) {
|
2016-01-08 21:49:43 +00:00
|
|
|
testRequires(c, DaemonIsLinux)
|
2015-12-30 19:52:53 +00:00
|
|
|
dockerCmd(c, "run", "--name=testcont", "-d", "busybox", "top")
|
|
|
|
dockerCmd(c, "commit", "-m", "test comment", "testcont", "testimg")
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--format='{{.Comment}}'", "testimg")
|
|
|
|
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, "test comment")
|
|
|
|
}
|
2016-01-14 05:46:59 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
contName := "test1"
|
|
|
|
dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
|
2016-06-06 08:28:52 +00:00
|
|
|
netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
|
2016-01-28 14:19:25 +00:00
|
|
|
out := inspectField(c, contName, "NetworkSettings.Networks")
|
2016-01-14 05:46:59 +00:00
|
|
|
c.Assert(out, checker.Contains, "bridge")
|
2016-01-28 14:19:25 +00:00
|
|
|
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
|
2016-01-14 05:46:59 +00:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerNetworkCustom(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
netOut, _ := dockerCmd(c, "network", "create", "net1")
|
|
|
|
dockerCmd(c, "run", "--name=container1", "--net=net1", "-d", "busybox", "top")
|
2016-01-28 14:19:25 +00:00
|
|
|
out := inspectField(c, "container1", "NetworkSettings.Networks")
|
2016-01-14 05:46:59 +00:00
|
|
|
c.Assert(out, checker.Contains, "net1")
|
2016-01-28 14:19:25 +00:00
|
|
|
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
|
2016-01-14 05:46:59 +00:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut))
|
|
|
|
}
|
2016-03-21 16:56:51 +00:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectRootFS(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "busybox")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
var imageJSON []types.ImageInspect
|
|
|
|
err = json.Unmarshal([]byte(out), &imageJSON)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
c.Assert(len(imageJSON[0].RootFS.Layers), checker.GreaterOrEqualThan, 1)
|
|
|
|
}
|