summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/run.go2
-rw-r--r--cmd/podman/start.go4
-rw-r--r--docs/tutorials/podman_tutorial.md29
-rw-r--r--libpod/container_api.go11
-rw-r--r--libpod/container_internal.go13
5 files changed, 44 insertions, 15 deletions
diff --git a/cmd/podman/run.go b/cmd/podman/run.go
index 97f60cdbf..2f3468fd2 100644
--- a/cmd/podman/run.go
+++ b/cmd/podman/run.go
@@ -145,5 +145,5 @@ func runCmd(c *cli.Context) error {
if createConfig.Rm {
return runtime.RemoveContainer(ctr, true)
}
- return ctr.CleanupStorage()
+ return ctr.Cleanup()
}
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index 0dad5e237..18e8f7766 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -138,6 +138,10 @@ func startCmd(c *cli.Context) error {
} else {
exitCode = int(ecode)
}
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = ctr.Cleanup()
}
return lastError
}
diff --git a/docs/tutorials/podman_tutorial.md b/docs/tutorials/podman_tutorial.md
index 5e174ac6b..760047840 100644
--- a/docs/tutorials/podman_tutorial.md
+++ b/docs/tutorials/podman_tutorial.md
@@ -101,19 +101,16 @@ $ sudo podman ps
```
Note: If you add *-a* to the *ps* command, Podman will show all containers.
-
-### Executing a command in a running container
-You can use the *exec* subcommand to execute a command in a running container. Eventually you will be able to
-obtain the IP address of the container through inspection, but that is not enabled yet. Therefore, we will
-install *iproute* in the container. Notice here that we use the switch **--latest** as a shortcut for the latest
-created container. You could also use the container's ID listed during *podman ps* in the previous step or
-when you ran the container.
+### Inspecting a running container
+You can "inspect" a running container for metadata and details about itself. We can even use
+the inspect subcommand to see what IP address was assigned to the container.
```
-$ sudo podman exec --latest -t dnf -y install iproute
-$ sudo podman exec --latest -t ip a
+$ sudo podman inspect -l | grep IPAddress\":
+ "IPAddress": "10.88.6.140",
```
-Note the IP address of the *ethernet* device.
+Note: The -l is convenience arguement for **latest container**. You can also use the container's ID instead
+of -l.
### Testing the httpd server
Now that we have the IP address of the container, we can test the network communication between the host
@@ -127,14 +124,22 @@ containerized httpd server.
You can view the container's logs with Podman as well:
```
$ sudo podman logs --latest
+10.88.0.1 - - [07/Feb/2018:15:22:11 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
+10.88.0.1 - - [07/Feb/2018:15:22:30 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
+10.88.0.1 - - [07/Feb/2018:15:22:30 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
+10.88.0.1 - - [07/Feb/2018:15:22:31 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
+10.88.0.1 - - [07/Feb/2018:15:22:31 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.55.1" "-"
```
-<!-- (
### Viewing the container's pids
And you can observe the httpd pid in the container with *top*.
```
$ sudo podman top <container_id>
-``` ) -->
+ UID PID PPID C STIME TTY TIME CMD
+ 0 31873 31863 0 09:21 ? 00:00:00 nginx: master process nginx -g daemon off;
+ 101 31889 31873 0 09:21 ? 00:00:00 nginx: worker process
+```
+
### Stopping the container
To stop the httpd container:
```
diff --git a/libpod/container_api.go b/libpod/container_api.go
index 3693ab78b..72df60eb8 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -694,8 +694,9 @@ func (c *Container) Wait() (int32, error) {
return exitCode, nil
}
-// CleanupStorage unmounts all mount points in container and cleans up container storage
-func (c *Container) CleanupStorage() error {
+// Cleanup unmounts all mount points in container and cleans up container storage
+// It also cleans up the network stack
+func (c *Container) Cleanup() error {
if !c.locked {
c.lock.Lock()
defer c.lock.Unlock()
@@ -703,6 +704,12 @@ func (c *Container) CleanupStorage() error {
return err
}
}
+
+ // Stop the container's network namespace (if it has one)
+ if err := c.cleanupNetwork(); err != nil {
+ logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
+ }
+
return c.cleanupStorage()
}
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 77e456fe1..d434630a3 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -365,6 +365,19 @@ func (c *Container) mountStorage() (err error) {
return c.save()
}
+// cleanupNetwork unmounts and cleans up the container's network
+func (c *Container) cleanupNetwork() error {
+ // Stop the container's network namespace (if it has one)
+ if err := c.runtime.teardownNetNS(c); err != nil {
+ logrus.Errorf("unable cleanup network for container %s: %q", c.ID(), err)
+ }
+
+ c.state.NetNS = nil
+ c.state.SubnetMask = ""
+ c.state.IPAddress = ""
+ return c.save()
+}
+
// cleanupStorage unmounts and cleans up the container's root filesystem
func (c *Container) cleanupStorage() error {
if !c.state.Mounted {