Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"encoding/json" |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"os/exec" |
| 7 |
+ "runtime" |
|
| 7 | 8 |
"strconv" |
| 8 | 9 |
"strings" |
| 9 | 10 |
"time" |
| ... | ... |
@@ -73,6 +74,7 @@ func (s *DockerSuite) TestStoppedContainerStatsGoroutines(c *check.C) {
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 | 75 |
func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
| 76 |
+ testRequires(c, SameHostDaemon) |
|
| 76 | 77 |
// Run container for 30 secs |
| 77 | 78 |
out, _ := dockerCmd(c, "run", "-d", "busybox", "top") |
| 78 | 79 |
id := strings.TrimSpace(out) |
| ... | ... |
@@ -85,7 +87,12 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
| 85 | 85 |
|
| 86 | 86 |
// Get the container networking stats before and after pinging the container |
| 87 | 87 |
nwStatsPre := getNetworkStats(c, id) |
| 88 |
- _, err = exec.Command("ping", contIP, "-c", strconv.Itoa(numPings)).Output()
|
|
| 88 |
+ countParam := "-c" |
|
| 89 |
+ if runtime.GOOS == "windows" {
|
|
| 90 |
+ countParam = "-n" // Ping count parameter is -n on Windows |
|
| 91 |
+ } |
|
| 92 |
+ pingout, err := exec.Command("ping", contIP, countParam, strconv.Itoa(numPings)).Output()
|
|
| 93 |
+ pingouts := string(pingout[:]) |
|
| 89 | 94 |
c.Assert(err, check.IsNil) |
| 90 | 95 |
nwStatsPost := getNetworkStats(c, id) |
| 91 | 96 |
|
| ... | ... |
@@ -93,9 +100,9 @@ func (s *DockerSuite) TestApiNetworkStats(c *check.C) {
|
| 93 | 93 |
expRxPkts := 1 + nwStatsPre.RxPackets + uint64(numPings) |
| 94 | 94 |
expTxPkts := 1 + nwStatsPre.TxPackets + uint64(numPings) |
| 95 | 95 |
c.Assert(nwStatsPost.TxPackets >= expTxPkts, check.Equals, true, |
| 96 |
- check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d", expTxPkts, nwStatsPost.TxPackets))
|
|
| 96 |
+ check.Commentf("Reported less TxPackets than expected. Expected >= %d. Found %d. %s", expTxPkts, nwStatsPost.TxPackets, pingouts))
|
|
| 97 | 97 |
c.Assert(nwStatsPost.RxPackets >= expRxPkts, check.Equals, true, |
| 98 |
- check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d", expRxPkts, nwStatsPost.RxPackets))
|
|
| 98 |
+ check.Commentf("Reported less Txbytes than expected. Expected >= %d. Found %d. %s", expRxPkts, nwStatsPost.RxPackets, pingouts))
|
|
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
func getNetworkStats(c *check.C, id string) types.Network {
|
| ... | ... |
@@ -2,8 +2,6 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "io/ioutil" |
|
| 6 |
- "os" |
|
| 7 | 5 |
"os/exec" |
| 8 | 6 |
"reflect" |
| 9 | 7 |
"regexp" |
| ... | ... |
@@ -13,38 +11,6 @@ import ( |
| 13 | 13 |
"github.com/go-check/check" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
-func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
|
|
| 17 |
- runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") |
|
| 18 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 19 |
- if err != nil {
|
|
| 20 |
- c.Fatal(out, err) |
|
| 21 |
- } |
|
| 22 |
- |
|
| 23 |
- if !strings.HasPrefix(out, "-") {
|
|
| 24 |
- c.Errorf("/etc/hosts should be a regular file")
|
|
| 25 |
- } |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
|
|
| 29 |
- testRequires(c, SameHostDaemon) |
|
| 30 |
- |
|
| 31 |
- runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") |
|
| 32 |
- out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 33 |
- if err != nil {
|
|
| 34 |
- c.Fatal(out, err) |
|
| 35 |
- } |
|
| 36 |
- |
|
| 37 |
- hosts, err := ioutil.ReadFile("/etc/hosts")
|
|
| 38 |
- if os.IsNotExist(err) {
|
|
| 39 |
- c.Skip("/etc/hosts does not exist, skip this test")
|
|
| 40 |
- } |
|
| 41 |
- |
|
| 42 |
- if out != string(hosts) {
|
|
| 43 |
- c.Errorf("container")
|
|
| 44 |
- } |
|
| 45 |
- |
|
| 46 |
-} |
|
| 47 |
- |
|
| 48 | 16 |
func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) {
|
| 49 | 17 |
runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") |
| 50 | 18 |
exitCode, err := runCommand(runCmd) |
| ... | ... |
@@ -217,20 +183,6 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) {
|
| 217 | 217 |
|
| 218 | 218 |
} |
| 219 | 219 |
|
| 220 |
-func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
|
|
| 221 |
- |
|
| 222 |
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")) |
|
| 223 |
- if err != nil {
|
|
| 224 |
- c.Fatal(err, out) |
|
| 225 |
- } |
|
| 226 |
- |
|
| 227 |
- out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")) |
|
| 228 |
- if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
|
|
| 229 |
- c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
|
|
| 230 |
- } |
|
| 231 |
- |
|
| 232 |
-} |
|
| 233 |
- |
|
| 234 | 220 |
func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) {
|
| 235 | 221 |
testRequires(c, SameHostDaemon, ExecSupport) |
| 236 | 222 |
|
| 237 | 223 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,58 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package main |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "io/ioutil" |
|
| 6 |
+ "os" |
|
| 7 |
+ "os/exec" |
|
| 8 |
+ "strings" |
|
| 9 |
+ |
|
| 10 |
+ "github.com/go-check/check" |
|
| 11 |
+) |
|
| 12 |
+ |
|
| 13 |
+func (s *DockerSuite) TestLinksEtcHostsRegularFile(c *check.C) {
|
|
| 14 |
+ runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts") |
|
| 15 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 16 |
+ if err != nil {
|
|
| 17 |
+ c.Fatal(out, err) |
|
| 18 |
+ } |
|
| 19 |
+ |
|
| 20 |
+ if !strings.HasPrefix(out, "-") {
|
|
| 21 |
+ c.Errorf("/etc/hosts should be a regular file")
|
|
| 22 |
+ } |
|
| 23 |
+} |
|
| 24 |
+ |
|
| 25 |
+func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
|
|
| 26 |
+ testRequires(c, SameHostDaemon) |
|
| 27 |
+ |
|
| 28 |
+ runCmd := exec.Command(dockerBinary, "run", "--net=host", "busybox", "cat", "/etc/hosts") |
|
| 29 |
+ out, _, _, err := runCommandWithStdoutStderr(runCmd) |
|
| 30 |
+ if err != nil {
|
|
| 31 |
+ c.Fatal(out, err) |
|
| 32 |
+ } |
|
| 33 |
+ |
|
| 34 |
+ hosts, err := ioutil.ReadFile("/etc/hosts")
|
|
| 35 |
+ if os.IsNotExist(err) {
|
|
| 36 |
+ c.Skip("/etc/hosts does not exist, skip this test")
|
|
| 37 |
+ } |
|
| 38 |
+ |
|
| 39 |
+ if out != string(hosts) {
|
|
| 40 |
+ c.Errorf("container")
|
|
| 41 |
+ } |
|
| 42 |
+ |
|
| 43 |
+} |
|
| 44 |
+ |
|
| 45 |
+func (s *DockerSuite) TestLinksNetworkHostContainer(c *check.C) {
|
|
| 46 |
+ |
|
| 47 |
+ out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")) |
|
| 48 |
+ if err != nil {
|
|
| 49 |
+ c.Fatal(err, out) |
|
| 50 |
+ } |
|
| 51 |
+ |
|
| 52 |
+ out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")) |
|
| 53 |
+ if err == nil || !strings.Contains(out, "--net=host can't be used with links. This would result in undefined behavior") {
|
|
| 54 |
+ c.Fatalf("Running container linking to a container with --net host should have failed: %s", out)
|
|
| 55 |
+ } |
|
| 56 |
+ |
|
| 57 |
+} |
| ... | ... |
@@ -2,7 +2,6 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 |
- "net" |
|
| 6 | 5 |
"os/exec" |
| 7 | 6 |
"regexp" |
| 8 | 7 |
"sort" |
| ... | ... |
@@ -148,82 +147,6 @@ func assertPortList(c *check.C, out string, expected []string) bool {
|
| 148 | 148 |
return true |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 |
-func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
|
| 152 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", |
|
| 153 |
- "nc", "-l", "-p", "80") |
|
| 154 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 155 |
- if err != nil {
|
|
| 156 |
- c.Fatal(out, err) |
|
| 157 |
- } |
|
| 158 |
- firstID := strings.TrimSpace(out) |
|
| 159 |
- |
|
| 160 |
- runCmd = exec.Command(dockerBinary, "port", firstID, "80") |
|
| 161 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 162 |
- if err != nil {
|
|
| 163 |
- c.Fatal(out, err) |
|
| 164 |
- } |
|
| 165 |
- |
|
| 166 |
- if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
|
|
| 167 |
- c.Error("Port list is not correct")
|
|
| 168 |
- } |
|
| 169 |
- |
|
| 170 |
- runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 171 |
- "nc", "localhost", "9876") |
|
| 172 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 173 |
- c.Fatal(out, err) |
|
| 174 |
- } |
|
| 175 |
- |
|
| 176 |
- runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) |
|
| 177 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 178 |
- c.Fatal(out, err) |
|
| 179 |
- } |
|
| 180 |
- |
|
| 181 |
- runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 182 |
- "nc", "localhost", "9876") |
|
| 183 |
- if out, _, err = runCommandWithOutput(runCmd); err == nil {
|
|
| 184 |
- c.Error("Port is still bound after the Container is removed")
|
|
| 185 |
- } |
|
| 186 |
-} |
|
| 187 |
- |
|
| 188 |
-func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
|
| 189 |
- runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox", |
|
| 190 |
- "nc", "-l", "-p", "80") |
|
| 191 |
- out, _, err := runCommandWithOutput(runCmd) |
|
| 192 |
- if err != nil {
|
|
| 193 |
- c.Fatal(out, err) |
|
| 194 |
- } |
|
| 195 |
- firstID := strings.TrimSpace(out) |
|
| 196 |
- |
|
| 197 |
- runCmd = exec.Command(dockerBinary, "port", firstID, "80") |
|
| 198 |
- out, _, err = runCommandWithOutput(runCmd) |
|
| 199 |
- if err != nil {
|
|
| 200 |
- c.Fatal(out, err) |
|
| 201 |
- } |
|
| 202 |
- |
|
| 203 |
- _, exposedPort, err := net.SplitHostPort(out) |
|
| 204 |
- |
|
| 205 |
- if err != nil {
|
|
| 206 |
- c.Fatal(out, err) |
|
| 207 |
- } |
|
| 208 |
- |
|
| 209 |
- runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 210 |
- "nc", "localhost", strings.TrimSpace(exposedPort)) |
|
| 211 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 212 |
- c.Fatal(out, err) |
|
| 213 |
- } |
|
| 214 |
- |
|
| 215 |
- runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) |
|
| 216 |
- if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 217 |
- c.Fatal(out, err) |
|
| 218 |
- } |
|
| 219 |
- |
|
| 220 |
- runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 221 |
- "nc", "localhost", strings.TrimSpace(exposedPort)) |
|
| 222 |
- if out, _, err = runCommandWithOutput(runCmd); err == nil {
|
|
| 223 |
- c.Error("Port is still bound after the Container is removed")
|
|
| 224 |
- } |
|
| 225 |
-} |
|
| 226 |
- |
|
| 227 | 151 |
func stopRemoveContainer(id string, c *check.C) {
|
| 228 | 152 |
runCmd := exec.Command(dockerBinary, "rm", "-f", id) |
| 229 | 153 |
_, _, err := runCommandWithOutput(runCmd) |
| 230 | 154 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,87 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+package main |
|
| 3 |
+ |
|
| 4 |
+import ( |
|
| 5 |
+ "net" |
|
| 6 |
+ "os/exec" |
|
| 7 |
+ "strings" |
|
| 8 |
+ |
|
| 9 |
+ "github.com/go-check/check" |
|
| 10 |
+) |
|
| 11 |
+ |
|
| 12 |
+func (s *DockerSuite) TestPortHostBinding(c *check.C) {
|
|
| 13 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "-p", "9876:80", "busybox", |
|
| 14 |
+ "nc", "-l", "-p", "80") |
|
| 15 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 16 |
+ if err != nil {
|
|
| 17 |
+ c.Fatal(out, err) |
|
| 18 |
+ } |
|
| 19 |
+ firstID := strings.TrimSpace(out) |
|
| 20 |
+ |
|
| 21 |
+ runCmd = exec.Command(dockerBinary, "port", firstID, "80") |
|
| 22 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 23 |
+ if err != nil {
|
|
| 24 |
+ c.Fatal(out, err) |
|
| 25 |
+ } |
|
| 26 |
+ |
|
| 27 |
+ if !assertPortList(c, out, []string{"0.0.0.0:9876"}) {
|
|
| 28 |
+ c.Error("Port list is not correct")
|
|
| 29 |
+ } |
|
| 30 |
+ |
|
| 31 |
+ runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 32 |
+ "nc", "localhost", "9876") |
|
| 33 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 34 |
+ c.Fatal(out, err) |
|
| 35 |
+ } |
|
| 36 |
+ |
|
| 37 |
+ runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) |
|
| 38 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 39 |
+ c.Fatal(out, err) |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 43 |
+ "nc", "localhost", "9876") |
|
| 44 |
+ if out, _, err = runCommandWithOutput(runCmd); err == nil {
|
|
| 45 |
+ c.Error("Port is still bound after the Container is removed")
|
|
| 46 |
+ } |
|
| 47 |
+} |
|
| 48 |
+ |
|
| 49 |
+func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
|
|
| 50 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "-P", "--expose", "80", "busybox", |
|
| 51 |
+ "nc", "-l", "-p", "80") |
|
| 52 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 53 |
+ if err != nil {
|
|
| 54 |
+ c.Fatal(out, err) |
|
| 55 |
+ } |
|
| 56 |
+ firstID := strings.TrimSpace(out) |
|
| 57 |
+ |
|
| 58 |
+ runCmd = exec.Command(dockerBinary, "port", firstID, "80") |
|
| 59 |
+ out, _, err = runCommandWithOutput(runCmd) |
|
| 60 |
+ if err != nil {
|
|
| 61 |
+ c.Fatal(out, err) |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ _, exposedPort, err := net.SplitHostPort(out) |
|
| 65 |
+ |
|
| 66 |
+ if err != nil {
|
|
| 67 |
+ c.Fatal(out, err) |
|
| 68 |
+ } |
|
| 69 |
+ |
|
| 70 |
+ runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 71 |
+ "nc", "localhost", strings.TrimSpace(exposedPort)) |
|
| 72 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 73 |
+ c.Fatal(out, err) |
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 76 |
+ runCmd = exec.Command(dockerBinary, "rm", "-f", firstID) |
|
| 77 |
+ if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
|
| 78 |
+ c.Fatal(out, err) |
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ runCmd = exec.Command(dockerBinary, "run", "--net=host", "busybox", |
|
| 82 |
+ "nc", "localhost", strings.TrimSpace(exposedPort)) |
|
| 83 |
+ if out, _, err = runCommandWithOutput(runCmd); err == nil {
|
|
| 84 |
+ c.Error("Port is still bound after the Container is removed")
|
|
| 85 |
+ } |
|
| 86 |
+} |
| ... | ... |
@@ -294,85 +294,6 @@ func (s *DockerSuite) TestRunLinksContainerWithContainerId(c *check.C) {
|
| 294 | 294 |
} |
| 295 | 295 |
} |
| 296 | 296 |
|
| 297 |
-func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
|
|
| 298 |
- cmd := exec.Command(dockerBinary, "run", "--name", "test", "-d", "busybox", "top") |
|
| 299 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 300 |
- if err != nil {
|
|
| 301 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 302 |
- } |
|
| 303 |
- cmd = exec.Command(dockerBinary, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top") |
|
| 304 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 305 |
- if err != nil {
|
|
| 306 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 307 |
- } |
|
| 308 |
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=parent:parent", "busybox", "top") |
|
| 309 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 310 |
- if err != nil {
|
|
| 311 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 312 |
- } |
|
| 313 |
- |
|
| 314 |
- cmd = exec.Command(dockerBinary, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top") |
|
| 315 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 316 |
- if err != nil {
|
|
| 317 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 318 |
- } |
|
| 319 |
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=child:child", "busybox", "top") |
|
| 320 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 321 |
- if err != nil {
|
|
| 322 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 323 |
- } |
|
| 324 |
-} |
|
| 325 |
- |
|
| 326 |
-func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
|
|
| 327 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 328 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 329 |
- if err != nil {
|
|
| 330 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 331 |
- } |
|
| 332 |
- |
|
| 333 |
- cmd = exec.Command(dockerBinary, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox") |
|
| 334 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 335 |
- if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
|
|
| 336 |
- c.Fatalf("run --net=container with --dns should error out")
|
|
| 337 |
- } |
|
| 338 |
- |
|
| 339 |
- cmd = exec.Command(dockerBinary, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox") |
|
| 340 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 341 |
- if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
|
|
| 342 |
- c.Fatalf("run --net=container with --mac-address should error out")
|
|
| 343 |
- } |
|
| 344 |
- |
|
| 345 |
- cmd = exec.Command(dockerBinary, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox") |
|
| 346 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 347 |
- if err == nil || !strings.Contains(out, "--add-host and the network mode") {
|
|
| 348 |
- c.Fatalf("run --net=container with --add-host should error out")
|
|
| 349 |
- } |
|
| 350 |
- |
|
| 351 |
-} |
|
| 352 |
- |
|
| 353 |
-func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
|
|
| 354 |
- testRequires(c, ExecSupport) |
|
| 355 |
- cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top") |
|
| 356 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 357 |
- if err != nil {
|
|
| 358 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 359 |
- } |
|
| 360 |
- cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname") |
|
| 361 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 362 |
- if err != nil {
|
|
| 363 |
- c.Fatalf("failed to exec command: %v, output: %q", err, out)
|
|
| 364 |
- } |
|
| 365 |
- |
|
| 366 |
- cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") |
|
| 367 |
- out1, _, err := runCommandWithOutput(cmd) |
|
| 368 |
- if err != nil {
|
|
| 369 |
- c.Fatalf("failed to run container: %v, output: %q", err, out1)
|
|
| 370 |
- } |
|
| 371 |
- if out1 != out {
|
|
| 372 |
- c.Fatal("containers with shared net namespace should have same hostname")
|
|
| 373 |
- } |
|
| 374 |
-} |
|
| 375 |
- |
|
| 376 | 297 |
// Regression test for #4979 |
| 377 | 298 |
func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) {
|
| 378 | 299 |
runCmd := exec.Command(dockerBinary, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file") |
| ... | ... |
@@ -853,14 +774,6 @@ func (s *DockerSuite) TestRunContainerNetwork(c *check.C) {
|
| 853 | 853 |
} |
| 854 | 854 |
} |
| 855 | 855 |
|
| 856 |
-// Issue #4681 |
|
| 857 |
-func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
|
|
| 858 |
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 859 |
- if _, err := runCommand(cmd); err != nil {
|
|
| 860 |
- c.Fatal(err) |
|
| 861 |
- } |
|
| 862 |
-} |
|
| 863 |
- |
|
| 864 | 856 |
func (s *DockerSuite) TestRunNetHostNotAllowedWithLinks(c *check.C) {
|
| 865 | 857 |
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "linked", "busybox", "true")) |
| 866 | 858 |
if err != nil {
|
| ... | ... |
@@ -873,33 +786,6 @@ func (s *DockerSuite) TestRunNetHostNotAllowedWithLinks(c *check.C) {
|
| 873 | 873 |
} |
| 874 | 874 |
} |
| 875 | 875 |
|
| 876 |
-func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
|
|
| 877 |
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") |
|
| 878 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 879 |
- if err != nil {
|
|
| 880 |
- c.Fatal(err, out) |
|
| 881 |
- } |
|
| 882 |
- |
|
| 883 |
- var ( |
|
| 884 |
- count = 0 |
|
| 885 |
- parts = strings.Split(out, "\n") |
|
| 886 |
- ) |
|
| 887 |
- |
|
| 888 |
- for _, l := range parts {
|
|
| 889 |
- if l != "" {
|
|
| 890 |
- count++ |
|
| 891 |
- } |
|
| 892 |
- } |
|
| 893 |
- |
|
| 894 |
- if count != 1 {
|
|
| 895 |
- c.Fatalf("Wrong interface count in container %d", count)
|
|
| 896 |
- } |
|
| 897 |
- |
|
| 898 |
- if !strings.HasPrefix(out, "1: lo") {
|
|
| 899 |
- c.Fatalf("Wrong interface in test container: expected [1: lo], got %s", out)
|
|
| 900 |
- } |
|
| 901 |
-} |
|
| 902 |
- |
|
| 903 | 876 |
// #7851 hostname outside container shows FQDN, inside only shortname |
| 904 | 877 |
// For testing purposes it is not required to set host's hostname directly |
| 905 | 878 |
// and use "--net=host" (as the original issue submitter did), as the same |
| ... | ... |
@@ -2103,20 +1989,6 @@ func (s *DockerSuite) TestRunCidFileCheckIDLength(c *check.C) {
|
| 2103 | 2103 |
} |
| 2104 | 2104 |
} |
| 2105 | 2105 |
|
| 2106 |
-func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
|
|
| 2107 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top") |
|
| 2108 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 2109 |
- if err != nil {
|
|
| 2110 |
- c.Fatal(err) |
|
| 2111 |
- } |
|
| 2112 |
- id := strings.TrimSpace(out) |
|
| 2113 |
- res, err := inspectField(id, "NetworkSettings.IPAddress") |
|
| 2114 |
- c.Assert(err, check.IsNil) |
|
| 2115 |
- if res != "" {
|
|
| 2116 |
- c.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res)
|
|
| 2117 |
- } |
|
| 2118 |
-} |
|
| 2119 |
- |
|
| 2120 | 2106 |
func (s *DockerSuite) TestRunSetMacAddress(c *check.C) {
|
| 2121 | 2107 |
mac := "12:34:56:78:9a:bc" |
| 2122 | 2108 |
|
| ... | ... |
@@ -2616,14 +2488,6 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {
|
| 2616 | 2616 |
} |
| 2617 | 2617 |
} |
| 2618 | 2618 |
|
| 2619 |
-func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
|
|
| 2620 |
- cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true") |
|
| 2621 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 2622 |
- if err == nil || !strings.Contains(out, "cannot join own network") {
|
|
| 2623 |
- c.Fatalf("using container net mode to self should result in an error")
|
|
| 2624 |
- } |
|
| 2625 |
-} |
|
| 2626 |
- |
|
| 2627 | 2619 |
func (s *DockerSuite) TestRunModePidHost(c *check.C) {
|
| 2628 | 2620 |
testRequires(c, NativeExecDriver, SameHostDaemon) |
| 2629 | 2621 |
|
| ... | ... |
@@ -2882,26 +2746,6 @@ func (s *DockerSuite) TestRunAllowPortRangeThroughPublish(c *check.C) {
|
| 2882 | 2882 |
} |
| 2883 | 2883 |
} |
| 2884 | 2884 |
|
| 2885 |
-func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
|
| 2886 |
- testRequires(c, OomControl) |
|
| 2887 |
- errChan := make(chan error) |
|
| 2888 |
- go func() {
|
|
| 2889 |
- defer close(errChan) |
|
| 2890 |
- runCmd := exec.Command(dockerBinary, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") |
|
| 2891 |
- out, exitCode, _ := runCommandWithOutput(runCmd) |
|
| 2892 |
- if expected := 137; exitCode != expected {
|
|
| 2893 |
- errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out)
|
|
| 2894 |
- } |
|
| 2895 |
- }() |
|
| 2896 |
- |
|
| 2897 |
- select {
|
|
| 2898 |
- case err := <-errChan: |
|
| 2899 |
- c.Assert(err, check.IsNil) |
|
| 2900 |
- case <-time.After(30 * time.Second): |
|
| 2901 |
- c.Fatal("Timeout waiting for container to die on OOM")
|
|
| 2902 |
- } |
|
| 2903 |
-} |
|
| 2904 |
- |
|
| 2905 | 2885 |
func (s *DockerSuite) TestRunSetDefaultRestartPolicy(c *check.C) {
|
| 2906 | 2886 |
runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "test", "busybox", "top") |
| 2907 | 2887 |
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
| ... | ... |
@@ -3141,13 +2985,6 @@ func (s *DockerSuite) TestMountIntoSys(c *check.C) {
|
| 3141 | 3141 |
} |
| 3142 | 3142 |
} |
| 3143 | 3143 |
|
| 3144 |
-func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
|
|
| 3145 |
- dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top") |
|
| 3146 |
- dockerCmd(c, "run", "-d", "--net=host", "--name=second", "busybox", "top") |
|
| 3147 |
- dockerCmd(c, "stop", "first") |
|
| 3148 |
- dockerCmd(c, "stop", "second") |
|
| 3149 |
-} |
|
| 3150 |
- |
|
| 3151 | 3144 |
func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
|
| 3152 | 3145 |
testRequires(c, Apparmor, NativeExecDriver) |
| 3153 | 3146 |
|
| ... | ... |
@@ -3195,33 +3032,6 @@ func (s *DockerSuite) TestDevicePermissions(c *check.C) {
|
| 3195 | 3195 |
} |
| 3196 | 3196 |
} |
| 3197 | 3197 |
|
| 3198 |
-func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
|
|
| 3199 |
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 3200 |
- out, _, err := runCommandWithOutput(cmd) |
|
| 3201 |
- if err != nil {
|
|
| 3202 |
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 3203 |
- } |
|
| 3204 |
- |
|
| 3205 |
- cmd = exec.Command(dockerBinary, "run", "-p", "5000:5000", "--net=container:parent", "busybox") |
|
| 3206 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 3207 |
- if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
| 3208 |
- c.Fatalf("run --net=container with -p should error out")
|
|
| 3209 |
- } |
|
| 3210 |
- |
|
| 3211 |
- cmd = exec.Command(dockerBinary, "run", "-P", "--net=container:parent", "busybox") |
|
| 3212 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 3213 |
- if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
| 3214 |
- c.Fatalf("run --net=container with -P should error out")
|
|
| 3215 |
- } |
|
| 3216 |
- |
|
| 3217 |
- cmd = exec.Command(dockerBinary, "run", "--expose", "5000", "--net=container:parent", "busybox") |
|
| 3218 |
- out, _, err = runCommandWithOutput(cmd) |
|
| 3219 |
- if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
|
|
| 3220 |
- c.Fatalf("run --net=container with --expose should error out")
|
|
| 3221 |
- } |
|
| 3222 |
- |
|
| 3223 |
-} |
|
| 3224 |
- |
|
| 3225 | 3198 |
func (s *DockerSuite) TestRunCapAddCHOWN(c *check.C) {
|
| 3226 | 3199 |
cmd := exec.Command(dockerBinary, "run", "--cap-drop=ALL", "--cap-add=CHOWN", "busybox", "sh", "-c", "adduser -D -H newuser && chown newuser /home && echo ok") |
| 3227 | 3200 |
out, _, err := runCommandWithOutput(cmd) |
| ... | ... |
@@ -285,3 +285,193 @@ func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
| 285 | 285 |
c.Fatalf("setting the CPU CFS period failed")
|
| 286 | 286 |
} |
| 287 | 287 |
} |
| 288 |
+ |
|
| 289 |
+func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
|
| 290 |
+ testRequires(c, OomControl) |
|
| 291 |
+ errChan := make(chan error) |
|
| 292 |
+ go func() {
|
|
| 293 |
+ defer close(errChan) |
|
| 294 |
+ runCmd := exec.Command(dockerBinary, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done") |
|
| 295 |
+ out, exitCode, _ := runCommandWithOutput(runCmd) |
|
| 296 |
+ if expected := 137; exitCode != expected {
|
|
| 297 |
+ errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out)
|
|
| 298 |
+ } |
|
| 299 |
+ }() |
|
| 300 |
+ |
|
| 301 |
+ select {
|
|
| 302 |
+ case err := <-errChan: |
|
| 303 |
+ c.Assert(err, check.IsNil) |
|
| 304 |
+ case <-time.After(30 * time.Second): |
|
| 305 |
+ c.Fatal("Timeout waiting for container to die on OOM")
|
|
| 306 |
+ } |
|
| 307 |
+} |
|
| 308 |
+ |
|
| 309 |
+func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
|
|
| 310 |
+ cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true") |
|
| 311 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 312 |
+ if err == nil || !strings.Contains(out, "cannot join own network") {
|
|
| 313 |
+ c.Fatalf("using container net mode to self should result in an error")
|
|
| 314 |
+ } |
|
| 315 |
+} |
|
| 316 |
+ |
|
| 317 |
+func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
|
|
| 318 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 319 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 320 |
+ if err != nil {
|
|
| 321 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 322 |
+ } |
|
| 323 |
+ |
|
| 324 |
+ cmd = exec.Command(dockerBinary, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox") |
|
| 325 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 326 |
+ if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
|
|
| 327 |
+ c.Fatalf("run --net=container with --dns should error out")
|
|
| 328 |
+ } |
|
| 329 |
+ |
|
| 330 |
+ cmd = exec.Command(dockerBinary, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox") |
|
| 331 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 332 |
+ if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
|
|
| 333 |
+ c.Fatalf("run --net=container with --mac-address should error out")
|
|
| 334 |
+ } |
|
| 335 |
+ |
|
| 336 |
+ cmd = exec.Command(dockerBinary, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox") |
|
| 337 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 338 |
+ if err == nil || !strings.Contains(out, "--add-host and the network mode") {
|
|
| 339 |
+ c.Fatalf("run --net=container with --add-host should error out")
|
|
| 340 |
+ } |
|
| 341 |
+ |
|
| 342 |
+} |
|
| 343 |
+ |
|
| 344 |
+func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
|
|
| 345 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") |
|
| 346 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 347 |
+ if err != nil {
|
|
| 348 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 349 |
+ } |
|
| 350 |
+ |
|
| 351 |
+ cmd = exec.Command(dockerBinary, "run", "-p", "5000:5000", "--net=container:parent", "busybox") |
|
| 352 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 353 |
+ if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
| 354 |
+ c.Fatalf("run --net=container with -p should error out")
|
|
| 355 |
+ } |
|
| 356 |
+ |
|
| 357 |
+ cmd = exec.Command(dockerBinary, "run", "-P", "--net=container:parent", "busybox") |
|
| 358 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 359 |
+ if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
| 360 |
+ c.Fatalf("run --net=container with -P should error out")
|
|
| 361 |
+ } |
|
| 362 |
+ |
|
| 363 |
+ cmd = exec.Command(dockerBinary, "run", "--expose", "5000", "--net=container:parent", "busybox") |
|
| 364 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 365 |
+ if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
|
|
| 366 |
+ c.Fatalf("run --net=container with --expose should error out")
|
|
| 367 |
+ } |
|
| 368 |
+ |
|
| 369 |
+} |
|
| 370 |
+ |
|
| 371 |
+func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
|
|
| 372 |
+ cmd := exec.Command(dockerBinary, "run", "--name", "test", "-d", "busybox", "top") |
|
| 373 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 374 |
+ if err != nil {
|
|
| 375 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 376 |
+ } |
|
| 377 |
+ cmd = exec.Command(dockerBinary, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top") |
|
| 378 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 379 |
+ if err != nil {
|
|
| 380 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 381 |
+ } |
|
| 382 |
+ cmd = exec.Command(dockerBinary, "run", "-d", "--link=parent:parent", "busybox", "top") |
|
| 383 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 384 |
+ if err != nil {
|
|
| 385 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 386 |
+ } |
|
| 387 |
+ |
|
| 388 |
+ cmd = exec.Command(dockerBinary, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top") |
|
| 389 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 390 |
+ if err != nil {
|
|
| 391 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 392 |
+ } |
|
| 393 |
+ cmd = exec.Command(dockerBinary, "run", "-d", "--link=child:child", "busybox", "top") |
|
| 394 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 395 |
+ if err != nil {
|
|
| 396 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 397 |
+ } |
|
| 398 |
+} |
|
| 399 |
+ |
|
| 400 |
+func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
|
|
| 401 |
+ cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up") |
|
| 402 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 403 |
+ if err != nil {
|
|
| 404 |
+ c.Fatal(err, out) |
|
| 405 |
+ } |
|
| 406 |
+ |
|
| 407 |
+ var ( |
|
| 408 |
+ count = 0 |
|
| 409 |
+ parts = strings.Split(out, "\n") |
|
| 410 |
+ ) |
|
| 411 |
+ |
|
| 412 |
+ for _, l := range parts {
|
|
| 413 |
+ if l != "" {
|
|
| 414 |
+ count++ |
|
| 415 |
+ } |
|
| 416 |
+ } |
|
| 417 |
+ |
|
| 418 |
+ if count != 1 {
|
|
| 419 |
+ c.Fatalf("Wrong interface count in container %d", count)
|
|
| 420 |
+ } |
|
| 421 |
+ |
|
| 422 |
+ if !strings.HasPrefix(out, "1: lo") {
|
|
| 423 |
+ c.Fatalf("Wrong interface in test container: expected [1: lo], got %s", out)
|
|
| 424 |
+ } |
|
| 425 |
+} |
|
| 426 |
+ |
|
| 427 |
+// Issue #4681 |
|
| 428 |
+func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
|
|
| 429 |
+ cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1") |
|
| 430 |
+ if _, err := runCommand(cmd); err != nil {
|
|
| 431 |
+ c.Fatal(err) |
|
| 432 |
+ } |
|
| 433 |
+} |
|
| 434 |
+ |
|
| 435 |
+func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
|
|
| 436 |
+ testRequires(c, ExecSupport) |
|
| 437 |
+ cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top") |
|
| 438 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 439 |
+ if err != nil {
|
|
| 440 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
| 441 |
+ } |
|
| 442 |
+ cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname") |
|
| 443 |
+ out, _, err = runCommandWithOutput(cmd) |
|
| 444 |
+ if err != nil {
|
|
| 445 |
+ c.Fatalf("failed to exec command: %v, output: %q", err, out)
|
|
| 446 |
+ } |
|
| 447 |
+ |
|
| 448 |
+ cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname") |
|
| 449 |
+ out1, _, err := runCommandWithOutput(cmd) |
|
| 450 |
+ if err != nil {
|
|
| 451 |
+ c.Fatalf("failed to run container: %v, output: %q", err, out1)
|
|
| 452 |
+ } |
|
| 453 |
+ if out1 != out {
|
|
| 454 |
+ c.Fatal("containers with shared net namespace should have same hostname")
|
|
| 455 |
+ } |
|
| 456 |
+} |
|
| 457 |
+ |
|
| 458 |
+func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
|
|
| 459 |
+ cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top") |
|
| 460 |
+ out, _, err := runCommandWithOutput(cmd) |
|
| 461 |
+ if err != nil {
|
|
| 462 |
+ c.Fatal(err) |
|
| 463 |
+ } |
|
| 464 |
+ id := strings.TrimSpace(out) |
|
| 465 |
+ res, err := inspectField(id, "NetworkSettings.IPAddress") |
|
| 466 |
+ c.Assert(err, check.IsNil) |
|
| 467 |
+ if res != "" {
|
|
| 468 |
+ c.Fatalf("For 'none' mode network must not be initialized, but container got IP: %s", res)
|
|
| 469 |
+ } |
|
| 470 |
+} |
|
| 471 |
+ |
|
| 472 |
+func (s *DockerSuite) TestTwoContainersInNetHost(c *check.C) {
|
|
| 473 |
+ dockerCmd(c, "run", "-d", "--net=host", "--name=first", "busybox", "top") |
|
| 474 |
+ dockerCmd(c, "run", "-d", "--net=host", "--name=second", "busybox", "top") |
|
| 475 |
+ dockerCmd(c, "stop", "first") |
|
| 476 |
+ dockerCmd(c, "stop", "second") |
|
| 477 |
+} |
| ... | ... |
@@ -7,11 +7,9 @@ import ( |
| 7 | 7 |
"log" |
| 8 | 8 |
"net/http" |
| 9 | 9 |
"os/exec" |
| 10 |
- "path" |
|
| 11 | 10 |
"strings" |
| 12 | 11 |
"time" |
| 13 | 12 |
|
| 14 |
- "github.com/docker/libcontainer/cgroups" |
|
| 15 | 13 |
"github.com/go-check/check" |
| 16 | 14 |
) |
| 17 | 15 |
|
| ... | ... |
@@ -121,24 +119,6 @@ var ( |
| 121 | 121 |
}, |
| 122 | 122 |
"Test requires support for IPv6", |
| 123 | 123 |
} |
| 124 |
- OomControl = TestRequirement{
|
|
| 125 |
- func() bool {
|
|
| 126 |
- cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory")
|
|
| 127 |
- if err != nil {
|
|
| 128 |
- return false |
|
| 129 |
- } |
|
| 130 |
- if _, err := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes")); err != nil {
|
|
| 131 |
- return false |
|
| 132 |
- } |
|
| 133 |
- |
|
| 134 |
- if _, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.oom_control")); err != nil {
|
|
| 135 |
- return false |
|
| 136 |
- } |
|
| 137 |
- return true |
|
| 138 |
- |
|
| 139 |
- }, |
|
| 140 |
- "Test requires Oom control enabled.", |
|
| 141 |
- } |
|
| 142 | 124 |
) |
| 143 | 125 |
|
| 144 | 126 |
// testRequires checks if the environment satisfies the requirements |
| ... | ... |
@@ -36,4 +36,22 @@ var ( |
| 36 | 36 |
}, |
| 37 | 37 |
"Test requires an environment that supports cgroup cfs quota.", |
| 38 | 38 |
} |
| 39 |
+ OomControl = TestRequirement{
|
|
| 40 |
+ func() bool {
|
|
| 41 |
+ cgroupMemoryMountpoint, err := cgroups.FindCgroupMountpoint("memory")
|
|
| 42 |
+ if err != nil {
|
|
| 43 |
+ return false |
|
| 44 |
+ } |
|
| 45 |
+ if _, err := ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.memsw.limit_in_bytes")); err != nil {
|
|
| 46 |
+ return false |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ if _, err = ioutil.ReadFile(path.Join(cgroupMemoryMountpoint, "memory.oom_control")); err != nil {
|
|
| 50 |
+ return false |
|
| 51 |
+ } |
|
| 52 |
+ return true |
|
| 53 |
+ |
|
| 54 |
+ }, |
|
| 55 |
+ "Test requires Oom control enabled.", |
|
| 56 |
+ } |
|
| 39 | 57 |
) |
| ... | ... |
@@ -8,7 +8,7 @@ import ( |
| 8 | 8 |
func parseNetMode(netMode string) (NetworkMode, error) {
|
| 9 | 9 |
parts := strings.Split(netMode, ":") |
| 10 | 10 |
switch mode := parts[0]; mode {
|
| 11 |
- case "default": |
|
| 11 |
+ case "default", "none": |
|
| 12 | 12 |
default: |
| 13 | 13 |
return "", fmt.Errorf("invalid --net: %s", netMode)
|
| 14 | 14 |
} |