mirror of https://github.com/docker/docs.git
for ubuntu provision append hostname to 127.0.1.1 line in /etc/hosts
Signed-off-by: Aaron Welch <welch@packet.net>
This commit is contained in:
parent
30ae863a4b
commit
2a44f40f6c
|
@ -128,9 +128,17 @@ func (provisioner *UbuntuProvisioner) Hostname() (string, error) {
|
|||
|
||||
func (provisioner *UbuntuProvisioner) SetHostname(hostname string) error {
|
||||
if _, err := provisioner.SSHCommand(fmt.Sprintf(
|
||||
"sudo hostname %s && echo %q | sudo tee /etc/hostname && echo \"127.0.0.1 %s\" | sudo tee -a /etc/hosts",
|
||||
"sudo hostname %s && echo %q | sudo tee /etc/hostname",
|
||||
hostname,
|
||||
hostname,
|
||||
)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ubuntu/debian use 127.0.1.1 for non "localhost" loopback hostnames: https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution
|
||||
if _, err := provisioner.SSHCommand(fmt.Sprintf(
|
||||
"if grep -xq 127.0.1.1.* /etc/hosts; then sudo sed -i 's/^127.0.1.1.*/127.0.1.1 %s/g' /etc/hosts; else echo '127.0.1.1 %s' | sudo tee -a /etc/hosts; fi",
|
||||
hostname,
|
||||
hostname,
|
||||
)); err != nil {
|
||||
return err
|
||||
|
|
|
@ -52,6 +52,12 @@ export MACHINE_STORAGE_PATH=/tmp/machine-bats-test-$DRIVER
|
|||
run machine ssh $NAME -- docker version
|
||||
}
|
||||
|
||||
# currently this only checks debian/ubuntu style using 127.0.0.1
|
||||
@test "$DRIVER: hostname should be set properly" {
|
||||
run machine ssh $NAME -- "grep -Fxq '127.0.1.1 $NAME' /etc/hosts"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "$DRIVER: stop" {
|
||||
run machine stop $NAME
|
||||
[ "$status" -eq 0 ]
|
||||
|
|
Loading…
Reference in New Issue