@@ -17,7 +17,18 @@ var notFirstRun bool
17
17
var lastNotEmpty bool
18
18
19
19
// overridden by tests
20
- var resolvconfPath = resolvconf .Path
20
+ var resolvconfPath = func (netMode pb.NetMode ) string {
21
+ // The implementation of resolvconf.Path checks if systemd resolved is activated and chooses the internal
22
+ // resolv.conf (/run/systemd/resolve/resolv.conf) in such a case - see resolvconf_path.go of libnetwork.
23
+ // This, however, can be problematic, see https://github.com/moby/buildkit/issues/2404 and is not necessary
24
+ // in case the networking mode is set to host since the locally (127.0.0.53) running resolved daemon is
25
+ // accessible from inside a host networked container.
26
+ // For details of the implementation see https://github.com/moby/buildkit/pull/5207#discussion_r1705362230.
27
+ if netMode == pb .NetMode_HOST {
28
+ return "/etc/resolv.conf"
29
+ }
30
+ return resolvconf .Path ()
31
+ }
21
32
22
33
type DNSConfig struct {
23
34
Nameservers []string
@@ -44,7 +55,7 @@ func GetResolvConf(ctx context.Context, stateDir string, idmap *idtools.Identity
44
55
generate = true
45
56
}
46
57
if ! generate {
47
- fiMain , err := os .Stat (resolvconfPath ())
58
+ fiMain , err := os .Stat (resolvconfPath (netMode ))
48
59
if err != nil {
49
60
if ! errors .Is (err , os .ErrNotExist ) {
50
61
return struct {}{}, err
@@ -63,7 +74,7 @@ func GetResolvConf(ctx context.Context, stateDir string, idmap *idtools.Identity
63
74
return struct {}{}, nil
64
75
}
65
76
66
- dt , err := os .ReadFile (resolvconfPath ())
77
+ dt , err := os .ReadFile (resolvconfPath (netMode ))
67
78
if err != nil && ! errors .Is (err , os .ErrNotExist ) {
68
79
return struct {}{}, err
69
80
}
0 commit comments