зеркало из https://github.com/microsoft/docker.git
Remove nameserver 127.0.0.1 line rather then dumping resolv.conf
We have a bug report complaining about docker dumping the contents of the hosts resolv.conf if it container 127.0.0.1. They asked that instead of dropping the file altogether, that we just remove the line. This patch removes the 127.0.0.1 lines, if they exist and then checks if any nameserver lines exist. Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
This commit is contained in:
Родитель
d142b18aab
Коммит
65640994fd
|
@ -1044,6 +1044,7 @@ func (daemon *Daemon) checkLocaldns() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resolvConf = utils.RemoveLocalDns(resolvConf)
|
||||
if len(daemon.config.Dns) == 0 && utils.CheckLocalDns(resolvConf) {
|
||||
log.Infof("Local (127.0.0.1) DNS resolver found in resolv.conf and containers can't use it. Using default external servers : %v", DefaultDns)
|
||||
daemon.config.Dns = DefaultDns
|
||||
|
|
|
@ -27,3 +27,34 @@ func TestMergeLxcConfig(t *testing.T) {
|
|||
t.Fatalf("expected %s got %s", expected, cpuset)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLocalDns(t *testing.T) {
|
||||
ns0 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\n"
|
||||
|
||||
if result := utils.RemoveLocalDns([]byte(ns0)); result != nil {
|
||||
if ns0 != string(result) {
|
||||
t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
||||
}
|
||||
}
|
||||
|
||||
ns1 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\nnameserver 127.0.0.1\n"
|
||||
if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
|
||||
if ns0 != string(result) {
|
||||
t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
||||
}
|
||||
}
|
||||
|
||||
ns1 = "nameserver 10.16.60.14\nnameserver 127.0.0.1\nnameserver 10.16.60.21\n"
|
||||
if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
|
||||
if ns0 != string(result) {
|
||||
t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
||||
}
|
||||
}
|
||||
|
||||
ns1 = "nameserver 127.0.1.1\nnameserver 10.16.60.14\nnameserver 10.16.60.21\n"
|
||||
if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
|
||||
if ns0 != string(result) {
|
||||
t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -332,6 +333,16 @@ func CheckLocalDns(resolvConf []byte) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
var (
|
||||
localHostRx = regexp.MustCompile(`(?m)^nameserver 127[^\n]+\n*`)
|
||||
)
|
||||
|
||||
// RemoveLocalDns looks into the /etc/resolv.conf,
|
||||
// and removes any local nameserver entries.
|
||||
func RemoveLocalDns(resolvConf []byte) []byte {
|
||||
return localHostRx.ReplaceAll(resolvConf, []byte{})
|
||||
}
|
||||
|
||||
// GetLines parses input into lines and strips away comments.
|
||||
func GetLines(input []byte, commentMarker []byte) [][]byte {
|
||||
lines := bytes.Split(input, []byte("\n"))
|
||||
|
|
Загрузка…
Ссылка в новой задаче