diff --git a/libpod/container.go b/libpod/container.go index a6a509ae6c..3fba6c8819 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -741,14 +741,14 @@ func (c *Container) hostname(network bool) string { // containers.conf, use a sanitized version of the container's name // as the hostname. Since the container name must already match // the set '[a-zA-Z0-9][a-zA-Z0-9_.-]*', we can just remove any - // underscores and limit it to 253 characters to make it a valid + // underscores and limit it to 64 characters to make it a valid // hostname. if c.runtime.config.Containers.ContainerNameAsHostName { sanitizedHostname := strings.ReplaceAll(c.Name(), "_", "") - if len(sanitizedHostname) <= 253 { + if len(sanitizedHostname) <= 64 { return sanitizedHostname } - return sanitizedHostname[:253] + return sanitizedHostname[:64] } // Otherwise use the container's short ID as the hostname. diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go index fac038e096..98a4cfe669 100644 --- a/test/e2e/containers_conf_test.go +++ b/test/e2e/containers_conf_test.go @@ -788,7 +788,7 @@ var _ = Describe("Verify podman containers.conf usage", func() { }) startContainer := func(params ...string) string { - args := []string{"create"} + args := []string{"run", "-d"} for _, param := range params { if param == "--name" { args = append(args, "--replace") @@ -888,7 +888,7 @@ var _ = Describe("Verify podman containers.conf usage", func() { name = getContainerConfig(containerID, "{{ .Name }}") // Double check that name actually got set correctly Expect(name).To(Equal(longHostname)) - // Hostname should be the container name truncated to 253 characters - Expect(hostname).To(Equal(name[:253])) + // Hostname should be the container name truncated to 64 characters + Expect(hostname).To(Equal(name[:64])) }) })