diff options
Diffstat (limited to 'pkg/spec/createconfig.go')
-rw-r--r-- | pkg/spec/createconfig.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go index a39f4875c..57416732d 100644 --- a/pkg/spec/createconfig.go +++ b/pkg/spec/createconfig.go @@ -318,6 +318,14 @@ func (c *CreateConfig) GetContainerCreateOptions(runtime *libpod.Runtime) ([]lib logrus.Debugf("appending name %s", c.Name) options = append(options, libpod.WithName(c.Name)) } + if c.Pod != "" { + logrus.Debugf("adding container to pod %s", c.Pod) + pod, err := runtime.LookupPod(c.Pod) + if err != nil { + return nil, errors.Wrapf(err, "unable to add container to pod %s", c.Pod) + } + options = append(options, runtime.WithPod(pod)) + } if len(c.PortBindings) > 0 { portBindings, err = c.CreatePortBindings() @@ -351,9 +359,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 +382,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() { |