Skip to content

Commit a275ca2

Browse files
Tibor Vassvieux
authored andcommitted
plugins: support for host networking
Signed-off-by: Tibor Vass <tibor@docker.com> (cherry picked from commit 99124c0) Signed-off-by: Victor Vieux <victorvieux@gmail.com>
1 parent c28c634 commit a275ca2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

plugin/v2/plugin.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,34 @@ func (p *Plugin) InitSpec(s specs.Spec, libRoot string) (*specs.Spec, error) {
311311
Type: "bind",
312312
Options: []string{"rbind", "rshared"},
313313
})
314+
315+
if p.PluginObj.Config.Network.Type != "" {
316+
// TODO: if net == bridge, use libnetwork controller to create a new plugin-specific bridge, bind mount /etc/hosts and /etc/resolv.conf look at the docker code (allocateNetwork, initialize)
317+
if p.PluginObj.Config.Network.Type == "host" {
318+
for i, n := range s.Linux.Namespaces {
319+
if n.Type == "network" {
320+
s.Linux.Namespaces = append(s.Linux.Namespaces[:i], s.Linux.Namespaces[i+1:]...)
321+
break
322+
}
323+
}
324+
}
325+
etcHosts := "/etc/hosts"
326+
resolvConf := "/etc/resolv.conf"
327+
mounts = append(mounts,
328+
types.PluginMount{
329+
Source: &etcHosts,
330+
Destination: etcHosts,
331+
Type: "bind",
332+
Options: []string{"rbind", "ro"},
333+
},
334+
types.PluginMount{
335+
Source: &resolvConf,
336+
Destination: resolvConf,
337+
Type: "bind",
338+
Options: []string{"rbind", "ro"},
339+
})
340+
}
341+
314342
for _, mount := range mounts {
315343
m := specs.Mount{
316344
Destination: mount.Destination,

0 commit comments

Comments
 (0)