Allow containers to join the net namespace of other conatiners
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
acff50596b
commit
a740cd779e
1 changed files with 1 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue