diff --git a/api/client/system/inspect.go b/api/client/system/inspect.go index f6b1189c69..1866a90ea8 100644 --- a/api/client/system/inspect.go +++ b/api/client/system/inspect.go @@ -2,6 +2,7 @@ package system import ( "fmt" + "strings" "golang.org/x/net/context" @@ -85,14 +86,18 @@ func inspectAll(ctx context.Context, dockerCli *client.DockerCli, getSize bool) return i, rawImage, err } - // Search for task with that id if an image doesn't exists. + // Search for task with that id if an image doesn't exist. t, rawTask, err := client.TaskInspectWithRaw(ctx, ref) - if err == nil || !apiclient.IsErrNotFound(err) { + if err == nil || !(apiclient.IsErrNotFound(err) || isErrorNoSwarmMode(err)) { if getSize { fmt.Fprintln(dockerCli.Err(), "WARNING: --size ignored for tasks") } return t, rawTask, err } - return nil, nil, fmt.Errorf("Error: No such image, container or task: %s", ref) + return nil, nil, fmt.Errorf("Error: No such container, image or task: %s", ref) } } + +func isErrorNoSwarmMode(err error) bool { + return strings.Contains(err.Error(), "This node is not a swarm manager") +} diff --git a/integration-cli/docker_cli_by_digest_test.go b/integration-cli/docker_cli_by_digest_test.go index a62b251364..a007d99021 100644 --- a/integration-cli/docker_cli_by_digest_test.go +++ b/integration-cli/docker_cli_by_digest_test.go @@ -176,7 +176,7 @@ func (s *DockerRegistrySuite) TestRemoveImageByDigest(c *check.C) { _, err = inspectFieldWithError(imageReference, "Id") //unexpected nil err trying to inspect what should be a non-existent image c.Assert(err, checker.NotNil) - c.Assert(err.Error(), checker.Contains, "No such image") + c.Assert(err.Error(), checker.Contains, "No such container, image") } func (s *DockerRegistrySuite) TestBuildByDigest(c *check.C) { diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 36353cead5..a35bfcd41d 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -326,7 +326,7 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) { } // make sure the container is not running - runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", "top") + runningOut, err := s.d.Cmd("inspect", "--format={{.State.Running}}", "top") if err != nil { c.Fatalf("Could not inspect on container: %s, %v", out, err) } @@ -2196,7 +2196,7 @@ func (s *DockerDaemonSuite) TestCleanupMountsAfterDaemonCrash(c *check.C) { } // container should be running. - out, err = s.d.Cmd("inspect", "--format='{{.State.Running}}'", id) + out, err = s.d.Cmd("inspect", "--format={{.State.Running}}", id) c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) out = strings.TrimSpace(out) if out != "true" { diff --git a/integration-cli/docker_cli_external_graphdriver_unix_test.go b/integration-cli/docker_cli_external_graphdriver_unix_test.go index 771996bb11..c4a7281cc1 100644 --- a/integration-cli/docker_cli_external_graphdriver_unix_test.go +++ b/integration-cli/docker_cli_external_graphdriver_unix_test.go @@ -353,7 +353,7 @@ func (s *DockerExternalGraphdriverSuite) testExternalGraphDriver(name string, ex err = s.d.Restart("-s", name) - out, err = s.d.Cmd("inspect", "--format='{{.GraphDriver.Name}}'", "graphtest") + out, err = s.d.Cmd("inspect", "--format={{.GraphDriver.Name}}", "graphtest") c.Assert(err, check.IsNil, check.Commentf(out)) c.Assert(strings.TrimSpace(out), check.Equals, name) diff --git a/integration-cli/docker_cli_health_test.go b/integration-cli/docker_cli_health_test.go index d231965332..669edb330c 100644 --- a/integration-cli/docker_cli_health_test.go +++ b/integration-cli/docker_cli_health_test.go @@ -73,10 +73,10 @@ func (s *DockerSuite) TestHealth(c *check.C) { // Inspect the options out, _ = dockerCmd(c, "inspect", - "--format='timeout={{.Config.Healthcheck.Timeout}} "+ + "--format=timeout={{.Config.Healthcheck.Timeout}} "+ "interval={{.Config.Healthcheck.Interval}} "+ "retries={{.Config.Healthcheck.Retries}} "+ - "test={{.Config.Healthcheck.Test}}'", name) + "test={{.Config.Healthcheck.Test}}", name) c.Check(out, checker.Equals, "timeout=30s interval=1s retries=0 test=[CMD-SHELL cat /status]\n") // Start diff --git a/integration-cli/docker_cli_inspect_test.go b/integration-cli/docker_cli_inspect_test.go index fc5946987b..31d1883b08 100644 --- a/integration-cli/docker_cli_inspect_test.go +++ b/integration-cli/docker_cli_inspect_test.go @@ -85,7 +85,7 @@ func (s *DockerSuite) TestInspectTypeFlagContainer(c *check.C) { dockerCmd(c, "run", "--name=busybox", "-d", "busybox", "top") - formatStr := "--format='{{.State.Running}}'" + formatStr := "--format={{.State.Running}}" out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") c.Assert(out, checker.Equals, "true\n") // not a container JSON } @@ -137,7 +137,7 @@ func (s *DockerSuite) TestInspectImageFilterInt(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf("failed to inspect size of the image: %s, %v", out, err)) //now see if the size turns out to be the same - formatStr := fmt.Sprintf("--format='{{eq .Size %d}}'", size) + formatStr := fmt.Sprintf("--format={{eq .Size %d}}", size) out, _ = dockerCmd(c, "inspect", formatStr, imageTest) result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) c.Assert(err, checker.IsNil) @@ -159,7 +159,7 @@ func (s *DockerSuite) TestInspectContainerFilterInt(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf("failed to inspect exitcode of the container: %s, %v", out, err)) //now get the exit code to verify - formatStr := fmt.Sprintf("--format='{{eq .State.ExitCode %d}}'", exitCode) + formatStr := fmt.Sprintf("--format={{eq .State.ExitCode %d}}", exitCode) out, _ = dockerCmd(c, "inspect", formatStr, id) result, err := strconv.ParseBool(strings.TrimSuffix(out, "\n")) c.Assert(err, checker.IsNil) @@ -289,7 +289,7 @@ func (s *DockerSuite) TestInspectNoSizeFlagContainer(c *check.C) { runSleepingContainer(c, "--name=busybox", "-d") - formatStr := "--format='{{.SizeRw}},{{.SizeRootFs}}'" + formatStr := "--format={{.SizeRw}},{{.SizeRootFs}}" out, _ := dockerCmd(c, "inspect", "--type=container", formatStr, "busybox") c.Assert(strings.TrimSpace(out), check.Equals, ",", check.Commentf("Exepcted not to display size info: %s", out)) } @@ -333,7 +333,7 @@ func (s *DockerSuite) TestInspectTemplateError(c *check.C) { func (s *DockerSuite) TestInspectJSONFields(c *check.C) { runSleepingContainer(c, "--name=busybox", "-d") - out, _, err := dockerCmdWithError("inspect", "--type=container", "--format='{{.HostConfig.Dns}}'", "busybox") + out, _, err := dockerCmdWithError("inspect", "--type=container", "--format={{.HostConfig.Dns}}", "busybox") c.Assert(err, check.IsNil) c.Assert(out, checker.Equals, "[]\n") diff --git a/integration-cli/docker_cli_rename_test.go b/integration-cli/docker_cli_rename_test.go index 1ba620a5e1..f1a16fae52 100644 --- a/integration-cli/docker_cli_rename_test.go +++ b/integration-cli/docker_cli_rename_test.go @@ -63,7 +63,7 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) { name, err := inspectFieldWithError("first_name", "Name") c.Assert(err, checker.NotNil, check.Commentf(name)) - c.Assert(err.Error(), checker.Contains, "No such image, container or task: first_name") + c.Assert(err.Error(), checker.Contains, "No such container, image or task: first_name") } func (s *DockerSuite) TestRenameInvalidName(c *check.C) { @@ -129,7 +129,7 @@ func (s *DockerSuite) TestRenameContainerWithLinkedContainer(c *check.C) { db1, _ := dockerCmd(c, "run", "--name", "db1", "-d", "busybox", "top") dockerCmd(c, "run", "--name", "app1", "-d", "--link", "db1:/mysql", "busybox", "top") dockerCmd(c, "rename", "app1", "app2") - out, _, err := dockerCmdWithError("inspect", "--format='{{ .Id }}'", "app2/mysql") + out, _, err := dockerCmdWithError("inspect", "--format={{ .Id }}", "app2/mysql") c.Assert(err, checker.IsNil) c.Assert(strings.TrimSpace(out), checker.Equals, strings.TrimSpace(db1)) } diff --git a/integration-cli/docker_cli_userns_test.go b/integration-cli/docker_cli_userns_test.go index f8b3f77b61..1be80f64dd 100644 --- a/integration-cli/docker_cli_userns_test.go +++ b/integration-cli/docker_cli_userns_test.go @@ -45,7 +45,7 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) { user := s.findUser(c, "userns") c.Assert(uidgid[0], checker.Equals, user) - pid, err := s.d.Cmd("inspect", "--format='{{.State.Pid}}'", "userns") + pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns") c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid)) // check the uid and gid maps for the PID to ensure root is remapped // (cmd = cat /proc//uid_map | grep -E '0\s+9999\s+1')