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 {
|
func (v *NetNS) Create(n *libcontainer.Network, nspid int, context libcontainer.Context) error {
|
||||||
nsname, exists := n.Context["nsname"]
|
context["nspath"] = n.Context["nspath"]
|
||||||
|
|
||||||
if !exists {
|
|
||||||
return fmt.Errorf("nspath does not exist in network context")
|
|
||||||
}
|
|
||||||
|
|
||||||
context["nspath"] = fmt.Sprintf("/var/run/netns/%s", nsname)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,12 +23,10 @@ func (v *NetNS) Initialize(config *libcontainer.Network, context libcontainer.Co
|
||||||
if !exists {
|
if !exists {
|
||||||
return fmt.Errorf("nspath does not exist in network context")
|
return fmt.Errorf("nspath does not exist in network context")
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.OpenFile(nspath, os.O_RDONLY, 0)
|
f, err := os.OpenFile(nspath, os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed get network namespace fd: %v", err)
|
return fmt.Errorf("failed get network namespace fd: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := system.Setns(f.Fd(), syscall.CLONE_NEWNET); err != nil {
|
if err := system.Setns(f.Fd(), syscall.CLONE_NEWNET); err != nil {
|
||||||
return fmt.Errorf("failed to setns current network namespace: %v", err)
|
return fmt.Errorf("failed to setns current network namespace: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue