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"
|
2016-05-25 16:56:36 -04:00
|
|
|
"os"
|
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
|
|
|
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/container"
|
2016-12-30 12:23:00 -05:00
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2017-08-23 17:01:29 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
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"
|
2015-11-18 17:20:54 -05: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 09:19:25 -05:00
|
|
|
id := inspectField(c, imageTest, "Id")
|
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-10-13 11:42:25 -04:00
|
|
|
dockerCmd(c, "run", "-d", "-m=300M", "--name", "inspectTest", "busybox", "true")
|
2016-01-28 09:19:25 -05:00
|
|
|
inspectOut := inspectField(c, "inspectTest", "HostConfig.Memory")
|
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) {
|
|
|
|
//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 03:29:39 -05:00
|
|
|
out, _ := dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "true")
|
|
|
|
containerID := strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
inspectOut := inspectField(c, "busybox", "Id")
|
2015-12-28 03:29:39 -05:00
|
|
|
c.Assert(strings.TrimSpace(inspectOut), checker.Equals, containerID)
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2015-07-27 20:48:27 -04:00
|
|
|
func (s *DockerSuite) TestInspectStatus(c *check.C) {
|
2017-04-16 17:39:30 -04:00
|
|
|
out := runSleepingContainer(c, "-d")
|
2015-07-27 20:48:27 -04:00
|
|
|
out = strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
inspectOut := inspectField(c, out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
2015-07-27 20:48:27 -04:00
|
|
|
|
2016-08-30 18:59:58 -04:00
|
|
|
// Windows does not support pause/unpause on Windows Server Containers.
|
|
|
|
// (RS1 does for Hyper-V Containers, but production CI is not setup for that)
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType != "windows" {
|
2016-08-30 18:59:58 -04:00
|
|
|
dockerCmd(c, "pause", out)
|
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
|
|
|
c.Assert(inspectOut, checker.Equals, "paused")
|
2015-07-27 20:48:27 -04:00
|
|
|
|
2016-08-30 18:59:58 -04:00
|
|
|
dockerCmd(c, "unpause", out)
|
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
|
|
|
c.Assert(inspectOut, checker.Equals, "running")
|
|
|
|
}
|
2015-07-27 20:48:27 -04:00
|
|
|
|
|
|
|
dockerCmd(c, "stop", out)
|
2016-01-28 09:19:25 -05:00
|
|
|
inspectOut = inspectField(c, out, "State.Status")
|
2015-10-05 19:48:31 -04:00
|
|
|
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) {
|
|
|
|
//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.
|
2016-08-30 18:59:58 -04:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2016-06-23 12:24:28 -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) {
|
|
|
|
//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) {
|
|
|
|
//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) {
|
|
|
|
//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"
|
2016-01-28 09:19:25 -05:00
|
|
|
out := inspectField(c, imageTest, "Size")
|
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
|
2016-06-23 12:24:28 -04:00
|
|
|
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) {
|
2016-12-13 15:21:51 -05:00
|
|
|
result := icmd.RunCmd(icmd.Cmd{
|
|
|
|
Command: []string{dockerBinary, "run", "-i", "-a", "stdin", "busybox", "cat"},
|
|
|
|
Stdin: strings.NewReader("blahblah"),
|
|
|
|
})
|
|
|
|
result.Assert(c, icmd.Success)
|
|
|
|
out := result.Stdout()
|
2015-03-26 15:43:00 -04:00
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
out = inspectField(c, id, "State.ExitCode")
|
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
|
2016-06-23 12:24:28 -04:00
|
|
|
formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode)
|
2015-07-20 02:55:40 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", formatStr, id)
|
2016-12-13 15:21:51 -05:00
|
|
|
inspectResult, err := strconv.ParseBool(strings.TrimSuffix(out, "\n"))
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-13 15:21:51 -05:00
|
|
|
c.Assert(inspectResult, 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) {
|
2016-02-17 12:18:18 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
2015-06-15 14:05:10 -04:00
|
|
|
imageTest := "emptyfs"
|
2016-01-28 09:19:25 -05:00
|
|
|
name := inspectField(c, imageTest, "GraphDriver.Name")
|
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
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
deviceID := inspectField(c, imageTest, "GraphDriver.Data.DeviceId")
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2016-01-28 09:19:25 -05: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
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
deviceSize := inspectField(c, imageTest, "GraphDriver.Data.DeviceSize")
|
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) {
|
2016-02-17 12:18:18 -05:00
|
|
|
testRequires(c, DaemonIsLinux, Devicemapper)
|
|
|
|
|
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)
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
name := inspectField(c, out, "GraphDriver.Name")
|
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
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
imageDeviceID := inspectField(c, "busybox", "GraphDriver.Data.DeviceId")
|
2015-12-14 19:52:15 -05:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
deviceID := inspectField(c, out, "GraphDriver.Data.DeviceId")
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2015-12-14 19:52:15 -05:00
|
|
|
c.Assert(imageDeviceID, checker.Not(checker.Equals), deviceID)
|
|
|
|
|
2016-01-28 09:19:25 -05: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
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
deviceSize := inspectField(c, out, "GraphDriver.Data.DeviceSize")
|
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) {
|
2016-05-25 16:56:36 -04:00
|
|
|
modifier := ",z"
|
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType == "windows" {
|
2016-05-25 16:56:36 -04:00
|
|
|
modifier = ""
|
|
|
|
// 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 15:21:38 -04:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
vol := inspectFieldJSON(c, "test", "Mounts")
|
2015-06-03 15:21:38 -04:00
|
|
|
|
|
|
|
var mp []types.MountPoint
|
2016-08-04 12:17:37 -04:00
|
|
|
err := json.Unmarshal([]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, "")
|
2016-05-25 16:56:36 -04:00
|
|
|
c.Assert(m.Source, checker.Equals, prefix+slash+"data")
|
|
|
|
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType != "windows" { // Windows does not set mode
|
2016-06-17 18:46:45 -04:00
|
|
|
c.Assert(m.Mode, checker.Equals, "ro"+modifier)
|
|
|
|
}
|
2015-10-05 19:48:31 -04:00
|
|
|
c.Assert(m.RW, checker.Equals, false)
|
2015-06-03 15:21:38 -04:00
|
|
|
}
|
2015-07-26 09:00:53 -04:00
|
|
|
|
2016-08-03 10:21:38 -04:00
|
|
|
func (s *DockerSuite) TestInspectNamedMountPoint(c *check.C) {
|
|
|
|
prefix, slash := getPrefixAndSlashFromDaemonPlatform()
|
|
|
|
|
|
|
|
dockerCmd(c, "run", "-d", "--name", "test", "-v", "data:"+prefix+slash+"data", "busybox", "cat")
|
|
|
|
|
|
|
|
vol := inspectFieldJSON(c, "test", "Mounts")
|
|
|
|
|
|
|
|
var mp []types.MountPoint
|
2016-08-04 12:17:37 -04:00
|
|
|
err := json.Unmarshal([]byte(vol), &mp)
|
2016-08-03 10:21:38 -04:00
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
// check that there is only one mountpoint
|
|
|
|
c.Assert(mp, checker.HasLen, 1)
|
|
|
|
|
|
|
|
m := mp[0]
|
|
|
|
|
|
|
|
c.Assert(m.Name, checker.Equals, "data")
|
|
|
|
c.Assert(m.Driver, checker.Equals, "local")
|
|
|
|
c.Assert(m.Source, checker.Not(checker.Equals), "")
|
|
|
|
c.Assert(m.Destination, checker.Equals, prefix+slash+"data")
|
|
|
|
c.Assert(m.RW, checker.Equals, true)
|
|
|
|
}
|
|
|
|
|
2015-07-26 09:00:53 -04:00
|
|
|
// #14947
|
|
|
|
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
|
|
|
|
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
id := strings.TrimSpace(out)
|
2016-01-28 09:19:25 -05:00
|
|
|
startedAt := inspectField(c, id, "State.StartedAt")
|
|
|
|
finishedAt := inspectField(c, id, "State.FinishedAt")
|
|
|
|
created := inspectField(c, id, "Created")
|
2015-07-26 09:00:53 -04:00
|
|
|
|
2016-01-28 09:19:25 -05: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
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
created = inspectField(c, "busybox", "Created")
|
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) {
|
|
|
|
dockerCmd(c, "create", "--name=test", "--log-opt", "max-file=42", "busybox")
|
2015-12-18 13:36:17 -05:00
|
|
|
var logConfig container.LogConfig
|
2015-08-17 11:35:34 -04:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
out := inspectFieldJSON(c, "test", "HostConfig.LogConfig")
|
2015-08-17 11:35:34 -04:00
|
|
|
|
2016-01-28 09:19:25 -05: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.
|
|
|
|
|
2016-02-24 13:17:25 -05:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2016-06-23 12:24:28 -04:00
|
|
|
formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}"
|
2015-09-25 08:49:02 -04:00
|
|
|
out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox")
|
2017-01-16 23:45:27 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), check.Equals, "<nil>,<nil>", check.Commentf("Expected not to display size info: %s", out))
|
2015-09-25 08:49:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectSizeFlagContainer(c *check.C) {
|
2016-02-24 13:17:25 -05:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2015-09-25 08:49:02 -04:00
|
|
|
|
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>")
|
|
|
|
}
|
|
|
|
|
2016-02-24 13:17:25 -05:00
|
|
|
func (s *DockerSuite) TestInspectTemplateError(c *check.C) {
|
2015-12-28 03:29:39 -05:00
|
|
|
// Template parsing error for both the container and image.
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2016-02-24 13:17:25 -05:00
|
|
|
runSleepingContainer(c, "--name=container1", "-d")
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2015-12-28 03:29:39 -05: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 08:49:02 -04:00
|
|
|
|
2015-12-28 03:29:39 -05:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
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) {
|
2016-02-24 13:17:25 -05:00
|
|
|
runSleepingContainer(c, "--name=busybox", "-d")
|
2016-06-23 12:24:28 -04:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox")
|
2015-11-06 17:22:48 -05:00
|
|
|
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
c.Assert(out, checker.Equals, "[]\n")
|
|
|
|
}
|
2015-12-03 16:55:18 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectByPrefix(c *check.C) {
|
2016-01-28 09:19:25 -05:00
|
|
|
id := inspectField(c, "busybox", "Id")
|
2015-12-03 16:55:18 -05:00
|
|
|
c.Assert(id, checker.HasPrefix, "sha256:")
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
id2 := inspectField(c, id[:12], "Id")
|
2015-12-03 16:55:18 -05:00
|
|
|
c.Assert(id, checker.Equals, id2)
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
|
2015-12-03 16:55:18 -05:00
|
|
|
c.Assert(id, checker.Equals, id3)
|
|
|
|
}
|
2015-12-07 22:04:38 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectStopWhenNotFound(c *check.C) {
|
2017-02-01 15:03:58 -05:00
|
|
|
runSleepingContainer(c, "--name=busybox1", "-d")
|
|
|
|
runSleepingContainer(c, "--name=busybox2", "-d")
|
|
|
|
result := dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "busybox1", "busybox2", "missing")
|
|
|
|
|
|
|
|
c.Assert(result.Error, checker.Not(check.IsNil))
|
|
|
|
c.Assert(result.Stdout(), checker.Contains, "busybox1")
|
|
|
|
c.Assert(result.Stdout(), checker.Contains, "busybox2")
|
|
|
|
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
|
|
|
|
|
|
|
|
// test inspect would not fast fail
|
|
|
|
result = dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "missing", "busybox1", "busybox2")
|
|
|
|
|
|
|
|
c.Assert(result.Error, checker.Not(check.IsNil))
|
|
|
|
c.Assert(result.Stdout(), checker.Contains, "busybox1")
|
|
|
|
c.Assert(result.Stdout(), checker.Contains, "busybox2")
|
|
|
|
c.Assert(result.Stderr(), checker.Contains, "Error: No such container: missing")
|
2015-12-07 22:04:38 -05:00
|
|
|
}
|
2015-12-30 14:52:53 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectHistory(c *check.C) {
|
2016-08-30 18:59:58 -04:00
|
|
|
dockerCmd(c, "run", "--name=testcont", "busybox", "echo", "hello")
|
2015-12-30 14:52:53 -05:00
|
|
|
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 00:46:59 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectContainerNetworkDefault(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
contName := "test1"
|
|
|
|
dockerCmd(c, "run", "--name", contName, "-d", "busybox", "top")
|
2016-06-06 04:28:52 -04:00
|
|
|
netOut, _ := dockerCmd(c, "network", "inspect", "--format={{.ID}}", "bridge")
|
2016-01-28 09:19:25 -05:00
|
|
|
out := inspectField(c, contName, "NetworkSettings.Networks")
|
2016-01-14 00:46:59 -05:00
|
|
|
c.Assert(out, checker.Contains, "bridge")
|
2016-01-28 09:19:25 -05:00
|
|
|
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
|
2016-01-14 00:46:59 -05: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 09:19:25 -05:00
|
|
|
out := inspectField(c, "container1", "NetworkSettings.Networks")
|
2016-01-14 00:46:59 -05:00
|
|
|
c.Assert(out, checker.Contains, "net1")
|
2016-01-28 09:19:25 -05:00
|
|
|
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
|
2016-01-14 00:46:59 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(netOut))
|
|
|
|
}
|
2016-03-21 12:56:51 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectRootFS(c *check.C) {
|
|
|
|
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)
|
|
|
|
}
|
2016-09-29 21:16:36 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectAmpersand(c *check.C) {
|
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
name := "test"
|
|
|
|
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
|
|
|
|
c.Assert(out, checker.Contains, `soanni&rtr`)
|
|
|
|
out, _ = dockerCmd(c, "inspect", name)
|
|
|
|
c.Assert(out, checker.Contains, `soanni&rtr`)
|
|
|
|
}
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestInspectPlugin(c *check.C) {
|
2016-12-12 15:46:36 -05:00
|
|
|
testRequires(c, DaemonIsLinux, IsAmd64, Network)
|
2016-11-29 20:31:29 -05:00
|
|
|
_, _, err := dockerCmdWithError("plugin", "install", "--grant-all-permissions", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-12 18:05:53 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-12 18:05:53 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
// Even without tag the inspect still work
|
2016-12-12 18:05:53 -05:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-12 18:05:53 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
c.Assert(err, checker.IsNil)
|
2016-12-12 18:05:53 -05:00
|
|
|
c.Assert(strings.TrimSpace(out), checker.Equals, pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
c.Assert(out, checker.Contains, pNameWithTag)
|
|
|
|
}
|
2016-12-06 13:29:48 -05:00
|
|
|
|
|
|
|
// Test case for 29185
|
|
|
|
func (s *DockerSuite) TestInspectUnknownObject(c *check.C) {
|
|
|
|
// This test should work on both Windows and Linux
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "foobar")
|
|
|
|
c.Assert(err, checker.NotNil)
|
|
|
|
c.Assert(out, checker.Contains, "Error: No such object: foobar")
|
|
|
|
c.Assert(err.Error(), checker.Contains, "Error: No such object: foobar")
|
|
|
|
}
|
2016-12-24 01:57:30 -05:00
|
|
|
|
2017-01-16 23:45:27 -05:00
|
|
|
func (s *DockerSuite) TestInspectInvalidReference(c *check.C) {
|
2016-12-24 01:57:30 -05:00
|
|
|
// This test should work on both Windows and Linux
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "FooBar")
|
|
|
|
c.Assert(err, checker.NotNil)
|
2017-07-19 10:20:13 -04:00
|
|
|
c.Assert(out, checker.Contains, "no such image: FooBar")
|
2016-12-24 01:57:30 -05:00
|
|
|
}
|