源码
src/net/conf.go
func initConfVal() {
...
if runtime.GOOS != "openbsd" {
confVal.nss = parseNSSConfFile("/etc/nsswitch.conf")
}
...
if os.IsNotExist(nss.err) || (nss.err == nil && len(srcs) == 0) {
if c.goos == "solaris" {
// illumos defaults to "nis [NOTFOUND=return] files"
return fallbackOrder
}
if c.goos == "linux" {
return hostLookupDNSFiles
}
return hostLookupFilesDNS
}
...
}
src/net/nss.go
func parseNSSConfFile(file string) *nssConf {
f, err := os.Open(file)
if err != nil {
return &nssConf{err: err}
}
defer f.Close()
return parseNSSConf(f)
}
原因
在 alpine 中/etc/nsswitch.conf 不存在,导致了先从 dns 查询,然后 file 查询