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"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
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"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
"gotest.tools/v3/icmd"
|
2014-07-01 21:52:59 -04:00
|
|
|
)
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
type DockerCLIInspectSuite struct {
|
|
|
|
ds *DockerSuite
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIInspectSuite) TearDownTest(c *testing.T) {
|
|
|
|
s.ds.TearDownTest(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *DockerCLIInspectSuite) OnTimeout(c *testing.T) {
|
|
|
|
s.ds.OnTimeout(c)
|
|
|
|
}
|
|
|
|
|
2019-09-09 17:05:55 -04:00
|
|
|
func checkValidGraphDriver(c *testing.T, name string) {
|
2015-10-05 19:48:31 -04:00
|
|
|
if name != "devicemapper" && name != "overlay" && name != "vfs" && name != "zfs" && name != "btrfs" && name != "aufs" {
|
|
|
|
c.Fatalf("%v is not a valid graph driver name", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImage(c *testing.T) {
|
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"
|
2022-08-22 13:53:07 -04:00
|
|
|
if containerdSnapshotterEnabled() {
|
2022-07-22 13:02:08 -04:00
|
|
|
// Under containerd ID of the image is the digest of the manifest list.
|
|
|
|
imageTestID = "sha256:e43ca824363c5c56016f6ede3a9035afe0e9bd43333215e0b0bde6193969725d"
|
|
|
|
}
|
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
id := inspectField(c, imageTest, "Id")
|
2014-10-14 16:06:06 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, id, imageTestID)
|
2014-07-01 21:52:59 -04:00
|
|
|
}
|
2015-04-22 21:28:07 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectInt64(c *testing.T) {
|
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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectOut, "314572800")
|
2015-04-22 21:28:07 -04:00
|
|
|
}
|
2015-03-26 15:43:00 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectDefault(c *testing.T) {
|
2019-11-27 09:36:45 -05: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-06-26 10:47:31 -04:00
|
|
|
|
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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(inspectOut), containerID)
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectStatus(c *testing.T) {
|
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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectOut, "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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectOut, "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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectOut, "running")
|
2016-08-30 18:59:58 -04:00
|
|
|
}
|
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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectOut, "exited")
|
2015-07-27 20:48:27 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagContainer(c *testing.T) {
|
2019-11-27 09:36:45 -05: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.
|
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")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, out, "true\n") // not a container JSON
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithNoContainer(c *testing.T) {
|
2019-11-27 09:36:45 -05: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-06-26 10:47:31 -04:00
|
|
|
|
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
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithImage(c *testing.T) {
|
2019-11-27 09:36:45 -05: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-06-26 10:47:31 -04:00
|
|
|
|
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")
|
2019-08-09 02:57:11 -04:00
|
|
|
// not an image JSON
|
2019-09-09 17:07:46 -04:00
|
|
|
assert.Assert(c, !strings.Contains(out, "State"))
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTypeFlagWithInvalidValue(c *testing.T) {
|
2019-11-27 09:36:45 -05: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-06-26 10:47:31 -04:00
|
|
|
|
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")
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err != nil, "%d", exitCode)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, exitCode, 1, fmt.Sprintf("%s", err))
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "not a valid value for --type"))
|
2015-06-26 10:47:31 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImageFilterInt(c *testing.T) {
|
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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to inspect size of the image: %s, %v", out, err)
|
2015-03-26 15:43:00 -04:00
|
|
|
|
2022-09-23 16:22:32 -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"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, result, true)
|
2015-03-26 15:43:00 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerFilterInt(c *testing.T) {
|
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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to inspect exitcode of the container: %s, %v", out, err)
|
2015-03-26 15:43:00 -04:00
|
|
|
|
2022-09-23 16:22:32 -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"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, inspectResult, true)
|
2015-03-26 15:43:00 -04:00
|
|
|
}
|
2015-06-15 14:05:10 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectImageGraphDriver(c *testing.T) {
|
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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "failed to inspect DeviceSize of the image: %s, %v", deviceSize, err)
|
2015-06-15 14:05:10 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerGraphDriver(c *testing.T) {
|
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
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, imageDeviceID != deviceID)
|
2015-12-14 19:52:15 -05:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
_, err := strconv.Atoi(deviceID)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "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
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-06-03 15:21:38 -04:00
|
|
|
|
2015-10-05 19:48:31 -04:00
|
|
|
// check that there is only one mountpoint
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(mp), 1)
|
2015-06-03 15:21:38 -04:00
|
|
|
|
|
|
|
m := mp[0]
|
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, m.Name, "")
|
|
|
|
assert.Equal(c, m.Driver, "")
|
|
|
|
assert.Equal(c, m.Source, prefix+slash+"data")
|
|
|
|
assert.Equal(c, m.Destination, prefix+slash+"data")
|
2018-01-15 09:32:06 -05:00
|
|
|
if testEnv.OSType != "windows" { // Windows does not set mode
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, m.Mode, "ro"+modifier)
|
2016-06-17 18:46:45 -04:00
|
|
|
}
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, m.RW, false)
|
2015-06-03 15:21:38 -04:00
|
|
|
}
|
2015-07-26 09:00:53 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
|
2016-08-03 10:21:38 -04:00
|
|
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-08-03 10:21:38 -04:00
|
|
|
|
|
|
|
// check that there is only one mountpoint
|
2019-09-09 17:05:57 -04:00
|
|
|
assert.Equal(c, len(mp), 1)
|
2016-08-03 10:21:38 -04:00
|
|
|
|
|
|
|
m := mp[0]
|
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, m.Name, "data")
|
|
|
|
assert.Equal(c, m.Driver, "local")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, m.Source != "")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, m.Destination, prefix+slash+"data")
|
|
|
|
assert.Equal(c, m.RW, true)
|
2016-08-03 10:21:38 -04:00
|
|
|
}
|
|
|
|
|
2015-07-26 09:00:53 -04:00
|
|
|
// #14947
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTimesAsRFC3339Nano(c *testing.T) {
|
2015-07-26 09:00:53 -04:00
|
|
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-07-26 09:00:53 -04:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, finishedAt)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-07-26 09:00:53 -04:00
|
|
|
_, err = time.Parse(time.RFC3339Nano, created)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2015-07-26 09:00:53 -04:00
|
|
|
}
|
2015-08-17 11:35:34 -04:00
|
|
|
|
|
|
|
// #15633
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectLogConfigNoType(c *testing.T) {
|
2015-08-17 11:35:34 -04:00
|
|
|
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)
|
2019-09-11 06:57:29 -04:00
|
|
|
assert.Assert(c, err == nil, "%v", out)
|
2015-08-17 11:35:34 -04:00
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, logConfig.Type, "json-file")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, logConfig.Config["max-file"], "42", fmt.Sprintf("%v", logConfig))
|
2015-08-17 11:35:34 -04:00
|
|
|
}
|
2015-09-25 08:49:02 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectNoSizeFlagContainer(c *testing.T) {
|
2019-11-27 09:36:45 -05:00
|
|
|
// 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.
|
2015-09-25 08:49:02 -04:00
|
|
|
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), "<nil>,<nil>", fmt.Sprintf("Expected not to display size info: %s", out))
|
2015-09-25 08:49:02 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectSizeFlagContainer(c *testing.T) {
|
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, ",")
|
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, strings.TrimSpace(sz[0]) != "<nil>")
|
|
|
|
assert.Assert(c, strings.TrimSpace(sz[1]) != "<nil>")
|
2015-09-25 08:49:02 -04:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectTemplateError(c *testing.T) {
|
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")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, err != nil)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
2015-12-28 03:29:39 -05:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--type=image", "--format='Format container: {{.ThisDoesNotExist}}'", "busybox")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, err != nil)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "Template parsing error"))
|
2015-09-25 08:49:02 -04:00
|
|
|
}
|
2015-11-06 17:22:48 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectJSONFields(c *testing.T) {
|
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
|
|
|
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, out, "[]\n")
|
2015-11-06 17:22:48 -05:00
|
|
|
}
|
2015-12-03 16:55:18 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectByPrefix(c *testing.T) {
|
2016-01-28 09:19:25 -05:00
|
|
|
id := inspectField(c, "busybox", "Id")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Assert(c, strings.HasPrefix(id, "sha256:"))
|
2015-12-03 16:55:18 -05:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
id2 := inspectField(c, id[:12], "Id")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, id, id2)
|
2015-12-03 16:55:18 -05:00
|
|
|
|
2016-01-28 09:19:25 -05:00
|
|
|
id3 := inspectField(c, strings.TrimPrefix(id, "sha256:")[:12], "Id")
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Equal(c, id, id3)
|
2015-12-03 16:55:18 -05:00
|
|
|
}
|
2015-12-07 22:04:38 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectStopWhenNotFound(c *testing.T) {
|
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")
|
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, result.Error != nil)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
|
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
|
|
|
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
2017-02-01 15:03:58 -05:00
|
|
|
// test inspect would not fast fail
|
|
|
|
result = dockerCmdWithResult("inspect", "--type=container", "--format='{{.Name}}'", "missing", "busybox1", "busybox2")
|
|
|
|
|
2019-09-09 17:05:56 -04:00
|
|
|
assert.Assert(c, result.Error != nil)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox1"))
|
|
|
|
assert.Assert(c, strings.Contains(result.Stdout(), "busybox2"))
|
|
|
|
assert.Assert(c, strings.Contains(result.Stderr(), "Error: No such container: missing"))
|
2015-12-07 22:04:38 -05:00
|
|
|
}
|
2015-12-30 14:52:53 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectHistory(c *testing.T) {
|
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")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "test comment"))
|
2015-12-30 14:52:53 -05:00
|
|
|
}
|
2016-01-14 00:46:59 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerNetworkDefault(c *testing.T) {
|
2016-01-14 00:46:59 -05:00
|
|
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "bridge"))
|
2016-01-28 09:19:25 -05:00
|
|
|
out = inspectField(c, contName, "NetworkSettings.Networks.bridge.NetworkID")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
2016-01-14 00:46:59 -05:00
|
|
|
}
|
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectContainerNetworkCustom(c *testing.T) {
|
2016-01-14 00:46:59 -05:00
|
|
|
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")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "net1"))
|
2016-01-28 09:19:25 -05:00
|
|
|
out = inspectField(c, "container1", "NetworkSettings.Networks.net1.NetworkID")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.Equal(c, strings.TrimSpace(out), strings.TrimSpace(netOut))
|
2016-01-14 00:46:59 -05:00
|
|
|
}
|
2016-03-21 12:56:51 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectRootFS(c *testing.T) {
|
2016-03-21 12:56:51 -04:00
|
|
|
out, _, err := dockerCmdWithError("inspect", "busybox")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-03-21 12:56:51 -04:00
|
|
|
|
|
|
|
var imageJSON []types.ImageInspect
|
|
|
|
err = json.Unmarshal([]byte(out), &imageJSON)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1)
|
2016-03-21 12:56:51 -04:00
|
|
|
}
|
2016-09-29 21:16:36 -04:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectAmpersand(c *testing.T) {
|
2016-09-29 21:16:36 -04:00
|
|
|
testRequires(c, DaemonIsLinux)
|
|
|
|
|
|
|
|
name := "test"
|
|
|
|
out, _ := dockerCmd(c, "run", "--name", name, "--env", `TEST_ENV="soanni&rtr"`, "busybox", "env")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
2016-09-29 21:16:36 -04:00
|
|
|
out, _ = dockerCmd(c, "inspect", name)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, `soanni&rtr`))
|
2016-09-29 21:16:36 -04:00
|
|
|
}
|
2016-11-29 20:31:29 -05:00
|
|
|
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectPlugin(c *testing.T) {
|
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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "--type", "plugin", "--format", "{{.Name}}", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), 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)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
2016-12-12 18:05:53 -05:00
|
|
|
out, _, err = dockerCmdWithError("inspect", "--format", "{{.Name}}", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
|
|
|
assert.Equal(c, strings.TrimSpace(out), pNameWithTag)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
_, _, err = dockerCmdWithError("plugin", "disable", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2016-11-29 20:31:29 -05:00
|
|
|
|
|
|
|
out, _, err = dockerCmdWithError("plugin", "remove", pNameWithTag)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, pNameWithTag))
|
2016-11-29 20:31:29 -05:00
|
|
|
}
|
2016-12-06 13:29:48 -05:00
|
|
|
|
|
|
|
// Test case for 29185
|
2022-06-16 17:32:10 -04:00
|
|
|
func (s *DockerCLIInspectSuite) TestInspectUnknownObject(c *testing.T) {
|
2016-12-06 13:29:48 -05:00
|
|
|
// This test should work on both Windows and Linux
|
|
|
|
out, _, err := dockerCmdWithError("inspect", "foobar")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "")
|
2019-09-09 17:08:22 -04:00
|
|
|
assert.Assert(c, strings.Contains(out, "Error: No such object: foobar"))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.ErrorContains(c, err, "Error: No such object: foobar")
|
2016-12-06 13:29:48 -05:00
|
|
|
}
|