Skip to content

Docker doesn't configure UTS namespace or /etc/hostname correctly #14282

@awh

Description

@awh

Edit: My assertion about setting domainname may be suspect; see phemmer's comment and discussion below. The issue of erroneously passing the FQDN to syscall.Sethostname remains however.

Environment

vagrant@vagrant-ubuntu-utopic-64:~$ docker --version
Docker version 1.7.0, build 0baf609

Problem

Docker accepts a fully qualified domain name as the argument to --hostname, and models separate Hostname and Domainname fields in runconfig.Config; however once inside libcontainer only Hostname is modelled, and this erroneously includes the domain name which is then fed into syscall.Sethostname with the following results:

vagrant@vagrant-ubuntu-utopic-64:~$ docker run --hostname test.example.com -ti ubuntu
root@test:/# hostname
test.example.com
root@test:/# domainname
(none)

This is not correct; the value passed to syscall.Sethostname should be the unqualified hostname, and the remainder to syscall.Setdomainname. This would yield the expected output:

vagrant@vagrant-ubuntu-utopic-64:~$ docker run --hostname test.example.com -ti ubuntu
root@test:/# hostname
test
root@test:/# domainname
example.com

Currently, libcontainer does not invoke syscall.Setdomainname at all, leaving the domain name parameter of the UTS namespace uninitialised.

Docker is also incorrectly generating an /etc/hostname file with the fully qualified name - again this should be the unqualified name, and the FQDN set by aliasing in /etc/hosts.

It could also be argued that --hostname should be renamed to --fqdn, or changed so that it admits only an unqualified name and companioned by a new --domainname option to set the remainder.

Finally, the error message is uninformative:

docker run --hostname 012345678901234567890123456789012345678901234567890123456789.example.com -ti ubuntu
Error response from daemon: Cannot start container c1bb14c2a10b2341c185aed804ab6f625ca7a1164ea90ea4fd37ea56b6e2bed0: [8] System error: invalid argument

Consequences

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions