summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/common.go3
-rw-r--r--cmd/podman/spec.go24
-rw-r--r--test/podman_networking.bats23
3 files changed, 39 insertions, 11 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index e6c2645c9..4b268dfff 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -324,7 +324,8 @@ var createFlags = []cli.Flag{
},
cli.StringFlag{
Name: "network",
- Usage: "Connect a container to a network (default 'default')",
+ Usage: "Connect a container to a network",
+ Value: "bridge",
},
cli.StringSliceFlag{
Name: "network-alias",
diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go
index 037b18950..e000467e2 100644
--- a/cmd/podman/spec.go
+++ b/cmd/podman/spec.go
@@ -73,15 +73,16 @@ func addPidNS(config *createConfig, g *generate.Generator) error {
func addNetNS(config *createConfig, g *generate.Generator) error {
netMode := config.NetMode
if netMode.IsHost() {
+ logrus.Debug("Using host netmode")
return g.RemoveLinuxNamespace(libpod.NetNamespace)
- }
- if netMode.IsNone() {
- return libpod.ErrNotImplemented
- }
- if netMode.IsBridge() {
- return libpod.ErrNotImplemented
- }
- if netMode.IsContainer() {
+ } else if netMode.IsNone() {
+ logrus.Debug("Using none netmode")
+ return nil
+ } else if netMode.IsBridge() {
+ logrus.Debug("Using bridge netmode")
+ return nil
+ } else if netMode.IsContainer() {
+ logrus.Debug("Using container netmode")
ctr, err := config.Runtime.LookupContainer(netMode.ConnectedContainer())
if err != nil {
return errors.Wrapf(err, "container %q not found", netMode.ConnectedContainer())
@@ -94,6 +95,8 @@ func addNetNS(config *createConfig, g *generate.Generator) error {
if err := g.AddOrReplaceLinuxNamespace(libpod.NetNamespace, nsPath); err != nil {
return err
}
+ } else {
+ return errors.Errorf("unknown network mode")
}
return nil
}
@@ -556,8 +559,9 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er
options = append(options, libpod.WithName(c.Name))
}
// TODO parse ports into libpod format and include
- // TODO should not happen if --net=host
- options = append(options, libpod.WithNetNS([]ocicni.PortMapping{}))
+ if !c.NetMode.IsHost() {
+ options = append(options, libpod.WithNetNS([]ocicni.PortMapping{}))
+ }
options = append(options, libpod.WithStopSignal(c.StopSignal))
options = append(options, libpod.WithStopTimeout(c.StopTimeout))
return options, nil
diff --git a/test/podman_networking.bats b/test/podman_networking.bats
new file mode 100644
index 000000000..017f24d8f
--- /dev/null
+++ b/test/podman_networking.bats
@@ -0,0 +1,23 @@
+#!/usr/bin/env bats
+
+load helpers
+
+function teardown() {
+ cleanup_test
+}
+
+function setup() {
+ copy_images
+}
+
+@test "test network connection with default bridge" {
+ run ${KPOD_BINARY} ${KPOD_OPTIONS} run -dt ${ALPINE} wget www.yahoo.com
+ echo "$output"
+ [ "$status" -eq 0 ]
+}
+
+@test "test network connection with host" {
+ run ${KPOD_BINARY} ${KPOD_OPTIONS} run -dt --network host ${ALPINE} wget www.yahoo.com
+ echo "$output"
+ [ "$status" -eq 0 ]
+}