Browse Source

Merge pull request #20200 from thockin/14282-hostname-domainname-v2

Don't smoosh hostname and domainname in API
David Calavera 9 years ago
parent
commit
ae75435dae

+ 1 - 10
container/container_unix.go

@@ -44,15 +44,10 @@ type Container struct {
 // Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM.
 // Sets PATH, HOSTNAME and if container.Config.Tty is set: TERM.
 // The defaults set here do not override the values in container.Config.Env
 // The defaults set here do not override the values in container.Config.Env
 func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
 func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
-	// if a domain name was specified, append it to the hostname (see #7851)
-	fullHostname := container.Config.Hostname
-	if container.Config.Domainname != "" {
-		fullHostname = fmt.Sprintf("%s.%s", fullHostname, container.Config.Domainname)
-	}
 	// Setup environment
 	// Setup environment
 	env := []string{
 	env := []string{
 		"PATH=" + system.DefaultPathEnv,
 		"PATH=" + system.DefaultPathEnv,
-		"HOSTNAME=" + fullHostname,
+		"HOSTNAME=" + container.Config.Hostname,
 	}
 	}
 	if container.Config.Tty {
 	if container.Config.Tty {
 		env = append(env, "TERM=xterm")
 		env = append(env, "TERM=xterm")
@@ -92,10 +87,6 @@ func (container *Container) BuildHostnameFile() error {
 		return err
 		return err
 	}
 	}
 	container.HostnamePath = hostnamePath
 	container.HostnamePath = hostnamePath
-
-	if container.Config.Domainname != "" {
-		return ioutil.WriteFile(container.HostnamePath, []byte(fmt.Sprintf("%s.%s\n", container.Config.Hostname, container.Config.Domainname)), 0644)
-	}
 	return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
 	return ioutil.WriteFile(container.HostnamePath, []byte(container.Config.Hostname+"\n"), 0644)
 }
 }
 
 

+ 0 - 7
daemon/container_operations.go

@@ -671,13 +671,6 @@ func (daemon *Daemon) initializeNetworking(container *container.Container) error
 		if err != nil {
 		if err != nil {
 			return err
 			return err
 		}
 		}
-
-		parts := strings.SplitN(container.Config.Hostname, ".", 2)
-		if len(parts) > 1 {
-			container.Config.Hostname = parts[0]
-			container.Config.Domainname = parts[1]
-		}
-
 	}
 	}
 
 
 	if err := daemon.allocateNetwork(container); err != nil {
 	if err := daemon.allocateNetwork(container); err != nil {

+ 1 - 0
docs/reference/api/docker_remote_api.md

@@ -127,6 +127,7 @@ This section lists each version from latest to oldest.  Each listing includes a
 * `GET /containers/(id or name)/stats` now returns `pids_stats`, if the kernel is >= 4.3 and the pids cgroup is supported.
 * `GET /containers/(id or name)/stats` now returns `pids_stats`, if the kernel is >= 4.3 and the pids cgroup is supported.
 * `POST /containers/create` now allows you to override usernamespaces remapping and use privileged options for the container.
 * `POST /containers/create` now allows you to override usernamespaces remapping and use privileged options for the container.
 * `POST /auth` now returns an `IdentityToken` when supported by a registry.
 * `POST /auth` now returns an `IdentityToken` when supported by a registry.
+* `POST /containers/create` with both `Hostname` and `Domainname` fields specified will result in the container's hostname being set to `Hostname`, rather than `Hostname.Domainname`.
 
 
 ### v1.22 API changes
 ### v1.22 API changes
 
 

+ 1 - 12
runconfig/opts/parse.go

@@ -241,16 +241,6 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
 		entrypoint = strslice.StrSlice{*flEntrypoint}
 		entrypoint = strslice.StrSlice{*flEntrypoint}
 	}
 	}
 
 
-	var (
-		domainname string
-		hostname   = *flHostname
-		parts      = strings.SplitN(hostname, ".", 2)
-	)
-	if len(parts) > 1 {
-		hostname = parts[0]
-		domainname = parts[1]
-	}
-
 	ports, portBindings, err := nat.ParsePortSpecs(flPublish.GetAll())
 	ports, portBindings, err := nat.ParsePortSpecs(flPublish.GetAll())
 	if err != nil {
 	if err != nil {
 		return nil, nil, nil, cmd, err
 		return nil, nil, nil, cmd, err
@@ -362,8 +352,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
 	}
 	}
 
 
 	config := &container.Config{
 	config := &container.Config{
-		Hostname:     hostname,
-		Domainname:   domainname,
+		Hostname:     *flHostname,
 		ExposedPorts: ports,
 		ExposedPorts: ports,
 		User:         *flUser,
 		User:         *flUser,
 		Tty:          *flTty,
 		Tty:          *flTty,

+ 4 - 4
runconfig/opts/parse_test.go

@@ -391,11 +391,11 @@ func TestParseHostname(t *testing.T) {
 	if config, _ := mustParse(t, hostname); config.Hostname != "hostname" && config.Domainname != "" {
 	if config, _ := mustParse(t, hostname); config.Hostname != "hostname" && config.Domainname != "" {
 		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
 		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
 	}
 	}
-	if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname" && config.Domainname != "domainname" {
-		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
+	if config, _ := mustParse(t, hostnameWithDomain); config.Hostname != "hostname.domainname" && config.Domainname != "" {
+		t.Fatalf("Expected the config to have 'hostname' as hostname.domainname, got '%v'", config.Hostname)
 	}
 	}
-	if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname" && config.Domainname != "domainname.tld" {
-		t.Fatalf("Expected the config to have 'hostname' as hostname, got '%v'", config.Hostname)
+	if config, _ := mustParse(t, hostnameWithDomainTld); config.Hostname != "hostname.domainname.tld" && config.Domainname != "" {
+		t.Fatalf("Expected the config to have 'hostname' as hostname.domainname.tld, got '%v'", config.Hostname)
 	}
 	}
 }
 }