mirror of
https://github.com/containers/podman.git
synced 2025-06-20 00:51:16 +08:00
Support multiple networks
This is a refresh of Dan William's PR #974 with a rebase and proper vendoring of ocicni and containernetworking/cni. It adds the ability to define multiple networks as so: podman run --network=net1,net2,foobar ... Signed-off-by: baude <bbaude@redhat.com> Closes: #1082 Approved by: baude
This commit is contained in:
@ -351,9 +351,20 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
|
||||
// does not have one
|
||||
options = append(options, libpod.WithEntrypoint(c.Entrypoint))
|
||||
|
||||
networks := make([]string, 0)
|
||||
userNetworks := c.NetMode.UserDefined()
|
||||
if userNetworks != "" {
|
||||
for _, netName := range strings.Split(userNetworks, ",") {
|
||||
if netName == "" {
|
||||
return nil, errors.Wrapf(err, "container networks %q invalid", networks)
|
||||
}
|
||||
networks = append(networks, netName)
|
||||
}
|
||||
}
|
||||
|
||||
if rootless.IsRootless() {
|
||||
if !c.NetMode.IsHost() && !c.NetMode.IsNone() {
|
||||
options = append(options, libpod.WithNetNS(portBindings, true))
|
||||
options = append(options, libpod.WithNetNS(portBindings, true, networks))
|
||||
}
|
||||
} else if c.NetMode.IsContainer() {
|
||||
connectedCtr, err := c.Runtime.LookupContainer(c.NetMode.ConnectedContainer())
|
||||
@ -363,8 +374,7 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib
|
||||
options = append(options, libpod.WithNetNSFrom(connectedCtr))
|
||||
} else if !c.NetMode.IsHost() && !c.NetMode.IsNone() {
|
||||
postConfigureNetNS := (len(c.IDMappings.UIDMap) > 0 || len(c.IDMappings.GIDMap) > 0) && !c.UsernsMode.IsHost()
|
||||
options = append(options, libpod.WithNetNS([]ocicni.PortMapping{}, postConfigureNetNS))
|
||||
options = append(options, libpod.WithNetNS(portBindings, postConfigureNetNS))
|
||||
options = append(options, libpod.WithNetNS(portBindings, postConfigureNetNS, networks))
|
||||
}
|
||||
|
||||
if c.PidMode.IsContainer() {
|
||||
|
Reference in New Issue
Block a user