From a740cd779e939fafbd9d98308847e9a5a25b26da Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 21 Mar 2014 00:48:17 +0000 Subject: [PATCH] Allow containers to join the net namespace of other conatiners Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- libcontainer/network/netns.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libcontainer/network/netns.go b/libcontainer/network/netns.go index 3eb8ee5..7e311f2 100644 --- a/libcontainer/network/netns.go +++ b/libcontainer/network/netns.go @@ -14,13 +14,7 @@ type NetNS struct { } func (v *NetNS) Create(n *libcontainer.Network, nspid int, context libcontainer.Context) error { - nsname, exists := n.Context["nsname"] - - if !exists { - return fmt.Errorf("nspath does not exist in network context") - } - - context["nspath"] = fmt.Sprintf("/var/run/netns/%s", nsname) + context["nspath"] = n.Context["nspath"] return nil } @@ -29,12 +23,10 @@ func (v *NetNS) Initialize(config *libcontainer.Network, context libcontainer.Co if !exists { return fmt.Errorf("nspath does not exist in network context") } - f, err := os.OpenFile(nspath, os.O_RDONLY, 0) if err != nil { return fmt.Errorf("failed get network namespace fd: %v", err) } - if err := system.Setns(f.Fd(), syscall.CLONE_NEWNET); err != nil { return fmt.Errorf("failed to setns current network namespace: %v", err) }