mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
More descriptive error when running a container with a too long hostname (#21445)
This fix tries to fix issues encountered when running a container with a hostname that is longer than HOST_NAME_MAX(64). Previously, `could not synchronise with container process` was generated as the length of the regex check was missing. This fix covers the length check so that a hostname that is longer than HOST_NAME_MAX(64) will be given a correct error message. Several unit tests cases and additional integration test cases are added as well. This fix closes #21445. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -4290,3 +4290,21 @@ func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) {
|
||||
out, _, err = dockerCmdWithError("run", "-v", "/foo:/bar:nocopy", "busybox", "true")
|
||||
c.Assert(err, checker.NotNil, check.Commentf(out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunTooLongHostname(c *check.C) {
|
||||
// Test case in #21445
|
||||
hostname1 := "this-is-a-way-too-long-hostname-but-it-should-give-a-nice-error.local"
|
||||
out, _, err := dockerCmdWithError("run", "--hostname", hostname1, "busybox", "echo", "test")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Expected docker run to fail!"))
|
||||
c.Assert(out, checker.Contains, "invalid hostname format for --hostname:", check.Commentf("Expected to have 'invalid hostname format for --hostname:' in the output, get: %s!", out))
|
||||
|
||||
// HOST_NAME_MAX=64 so 65 bytes will fail
|
||||
hostname2 := "this-is-a-hostname-with-65-bytes-so-it-should-give-an-error.local"
|
||||
out, _, err = dockerCmdWithError("run", "--hostname", hostname2, "busybox", "echo", "test")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Expected docker run to fail!"))
|
||||
c.Assert(out, checker.Contains, "invalid hostname format for --hostname:", check.Commentf("Expected to have 'invalid hostname format for --hostname:' in the output, get: %s!", out))
|
||||
|
||||
// 64 bytes will be OK
|
||||
hostname3 := "this-is-a-hostname-with-64-bytes-so-will-not-give-an-error.local"
|
||||
dockerCmd(c, "run", "--hostname", hostname3, "busybox", "echo", "test")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user