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