Browse Source

Fix exec form of HEALTHCHECK CMD

We attached the JSON flag to the wrong AST node, causing Docker to treat
the exec form ["binary", "arg"] as if the shell form "binary arg" had
been used. This failed if "ls" was not present.

Added a test to detect this.

Fixes #26174

Signed-off-by: Thomas Leonard <thomas.leonard@docker.com>
Thomas Leonard 8 years ago
parent
commit
e95b6b51da

+ 1 - 1
builder/dockerfile/parser/line_parsers.go

@@ -357,5 +357,5 @@ func parseHealthConfig(rest string, d *Directive) (*Node, map[string]bool, error
 		return nil, nil, err
 		return nil, nil, err
 	}
 	}
 
 
-	return &Node{Value: typ, Next: cmd, Attributes: attrs}, nil, err
+	return &Node{Value: typ, Next: cmd}, attrs, err
 }
 }

+ 15 - 0
integration-cli/docker_cli_health_test.go

@@ -149,4 +149,19 @@ func (s *DockerSuite) TestHealth(c *check.C) {
 	c.Check(last.ExitCode, checker.Equals, -1)
 	c.Check(last.ExitCode, checker.Equals, -1)
 	c.Check(last.Output, checker.Equals, "Health check exceeded timeout (1ms)")
 	c.Check(last.Output, checker.Equals, "Health check exceeded timeout (1ms)")
 	dockerCmd(c, "rm", "-f", "test")
 	dockerCmd(c, "rm", "-f", "test")
+
+	// Check JSON-format
+	_, err = buildImage(imageName,
+		`FROM busybox
+		RUN echo OK > /status
+		CMD ["/bin/sleep", "120"]
+		STOPSIGNAL SIGKILL
+		HEALTHCHECK --interval=1s --timeout=30s \
+		  CMD ["cat", "/my status"]`,
+		true)
+	c.Check(err, check.IsNil)
+	out, _ = dockerCmd(c, "inspect",
+		"--format={{.Config.Healthcheck.Test}}", imageName)
+	c.Check(out, checker.Equals, "[CMD cat /my status]\n")
+
 }
 }