|
@@ -88,11 +88,8 @@ func (s *DockerSuite) TestRunWithVolumesIsRecursive(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestRunWithUlimits(c *check.C) {
|
|
|
testRequires(c, NativeExecDriver)
|
|
|
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n"))
|
|
|
- if err != nil {
|
|
|
- c.Fatal(err, out)
|
|
|
- }
|
|
|
|
|
|
+ out, _ := dockerCmd(c, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n")
|
|
|
ul := strings.TrimSpace(out)
|
|
|
if ul != "42" {
|
|
|
c.Fatalf("expected `ulimit -n` to be 42, got %s", ul)
|
|
@@ -113,7 +110,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParent(c *check.C) {
|
|
|
c.Fatalf("unable to find self cpu cgroup path. CgroupsPath: %v", selfCgroupPaths)
|
|
|
}
|
|
|
|
|
|
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup"))
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup")
|
|
|
if err != nil {
|
|
|
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
|
|
}
|
|
@@ -138,8 +135,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupParentAbsPath(c *check.C) {
|
|
|
testRequires(c, NativeExecDriver)
|
|
|
|
|
|
cgroupParent := "/cgroup-parent/test"
|
|
|
-
|
|
|
- out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup"))
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "--cgroup-parent", cgroupParent, "--rm", "busybox", "cat", "/proc/self/cgroup")
|
|
|
if err != nil {
|
|
|
c.Fatalf("unexpected failure when running container with --cgroup-parent option - %s\n%v", string(out), err)
|
|
|
}
|
|
@@ -163,8 +159,7 @@ func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
|
|
|
testRequires(c, NativeExecDriver)
|
|
|
|
|
|
filename := "/sys/fs/cgroup/devices/test123"
|
|
|
- cmd := exec.Command(dockerBinary, "run", "busybox", "touch", filename)
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "busybox", "touch", filename)
|
|
|
if err == nil {
|
|
|
c.Fatal("expected cgroup mount point to be read-only, touch file should fail")
|
|
|
}
|
|
@@ -176,24 +171,13 @@ func (s *DockerSuite) TestRunContainerWithCgroupMountRO(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestRunDeviceDirectory(c *check.C) {
|
|
|
testRequires(c, NativeExecDriver)
|
|
|
- cmd := exec.Command(dockerBinary, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/")
|
|
|
-
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatal(err, out)
|
|
|
- }
|
|
|
|
|
|
+ out, _ := dockerCmd(c, "run", "--device", "/dev/snd:/dev/snd", "busybox", "sh", "-c", "ls /dev/snd/")
|
|
|
if actual := strings.Trim(out, "\r\n"); !strings.Contains(out, "timer") {
|
|
|
c.Fatalf("expected output /dev/snd/timer, received %s", actual)
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/")
|
|
|
-
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatal(err, out)
|
|
|
- }
|
|
|
-
|
|
|
+ out, _ = dockerCmd(c, "run", "--device", "/dev/snd:/dev/othersnd", "busybox", "sh", "-c", "ls /dev/othersnd/")
|
|
|
if actual := strings.Trim(out, "\r\n"); !strings.Contains(out, "seq") {
|
|
|
c.Fatalf("expected output /dev/othersnd/seq, received %s", actual)
|
|
|
}
|
|
@@ -269,8 +253,8 @@ func (s *DockerSuite) TestRunAttachDetach(c *check.C) {
|
|
|
// "test" should be printed
|
|
|
func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
|
|
testRequires(c, CpuCfsQuota)
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test")
|
|
|
- out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
|
|
+
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "--cpu-quota", "8000", "--name", "test", "busybox", "echo", "test")
|
|
|
if err != nil {
|
|
|
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
}
|
|
@@ -289,8 +273,8 @@ func (s *DockerSuite) TestRunEchoStdoutWithCPUQuota(c *check.C) {
|
|
|
|
|
|
func (s *DockerSuite) TestRunWithCpuPeriod(c *check.C) {
|
|
|
testRequires(c, CpuCfsPeriod)
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true")
|
|
|
- if _, err := runCommand(runCmd); err != nil {
|
|
|
+
|
|
|
+ if _, _, err := dockerCmdWithError(c, "run", "--cpu-period", "50000", "--name", "test", "busybox", "true"); err != nil {
|
|
|
c.Fatalf("failed to run container: %v", err)
|
|
|
}
|
|
|
|
|
@@ -306,8 +290,7 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
|
|
errChan := make(chan error)
|
|
|
go func() {
|
|
|
defer close(errChan)
|
|
|
- runCmd := exec.Command(dockerBinary, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done")
|
|
|
- out, exitCode, _ := runCommandWithOutput(runCmd)
|
|
|
+ out, exitCode, _ := dockerCmdWithError(c, "run", "-m", "4MB", "busybox", "sh", "-c", "x=a; while true; do x=$x$x$x$x; done")
|
|
|
if expected := 137; exitCode != expected {
|
|
|
errChan <- fmt.Errorf("wrong exit code for OOM container: expected %d, got %d (output: %q)", expected, exitCode, out)
|
|
|
}
|
|
@@ -322,102 +305,63 @@ func (s *DockerSuite) TestRunOOMExitCode(c *check.C) {
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "--name=me", "--net=container:me", "busybox", "true")
|
|
|
if err == nil || !strings.Contains(out, "cannot join own network") {
|
|
|
c.Fatalf("using container net mode to self should result in an error")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunContainerNetModeWithDnsMacHosts(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "-d", "--name", "parent", "busybox", "top")
|
|
|
if err != nil {
|
|
|
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err = dockerCmdWithError(c, "run", "--dns", "1.2.3.4", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "Conflicting options: --dns and the network mode") {
|
|
|
c.Fatalf("run --net=container with --dns should error out")
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err = dockerCmdWithError(c, "run", "--mac-address", "92:d0:c6:0a:29:33", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "--mac-address and the network mode") {
|
|
|
c.Fatalf("run --net=container with --mac-address should error out")
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err = dockerCmdWithError(c, "run", "--add-host", "test:192.168.2.109", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "--add-host and the network mode") {
|
|
|
c.Fatalf("run --net=container with --add-host should error out")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunContainerNetModeWithExposePort(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
+ dockerCmd(c, "run", "-d", "--name", "parent", "busybox", "top")
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "-p", "5000:5000", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "-p", "5000:5000", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
|
c.Fatalf("run --net=container with -p should error out")
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "-P", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err = dockerCmdWithError(c, "run", "-P", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "Conflicting options: -p, -P, --publish-all, --publish and the network mode (--net)") {
|
|
|
c.Fatalf("run --net=container with -P should error out")
|
|
|
}
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--expose", "5000", "--net=container:parent", "busybox")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
+ out, _, err = dockerCmdWithError(c, "run", "--expose", "5000", "--net=container:parent", "busybox")
|
|
|
if err == nil || !strings.Contains(out, "Conflicting options: --expose and the network mode (--expose)") {
|
|
|
c.Fatalf("run --net=container with --expose should error out")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunLinkToContainerNetMode(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "--name", "test", "-d", "busybox", "top")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=parent:parent", "busybox", "top")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
-
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
- cmd = exec.Command(dockerBinary, "run", "-d", "--link=child:child", "busybox", "top")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
+ dockerCmd(c, "run", "--name", "test", "-d", "busybox", "top")
|
|
|
+ dockerCmd(c, "run", "--name", "parent", "-d", "--net=container:test", "busybox", "top")
|
|
|
+ dockerCmd(c, "run", "-d", "--link=parent:parent", "busybox", "top")
|
|
|
+ dockerCmd(c, "run", "--name", "child", "-d", "--net=container:parent", "busybox", "top")
|
|
|
+ dockerCmd(c, "run", "-d", "--link=child:child", "busybox", "top")
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatal(err, out)
|
|
|
- }
|
|
|
+ out, _ := dockerCmd(c, "run", "--net=none", "busybox", "ip", "-o", "-4", "a", "show", "up")
|
|
|
|
|
|
var (
|
|
|
count = 0
|
|
@@ -441,41 +385,23 @@ func (s *DockerSuite) TestRunLoopbackOnlyExistsWhenNetworkingDisabled(c *check.C
|
|
|
|
|
|
// Issue #4681
|
|
|
func (s *DockerSuite) TestRunLoopbackWhenNetworkDisabled(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1")
|
|
|
- if _, err := runCommand(cmd); err != nil {
|
|
|
- c.Fatal(err)
|
|
|
- }
|
|
|
+ dockerCmd(c, "run", "--net=none", "busybox", "ping", "-c", "1", "127.0.0.1")
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunModeNetContainerHostname(c *check.C) {
|
|
|
testRequires(c, ExecSupport)
|
|
|
- cmd := exec.Command(dockerBinary, "run", "-i", "-d", "--name", "parent", "busybox", "top")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out)
|
|
|
- }
|
|
|
- cmd = exec.Command(dockerBinary, "exec", "parent", "cat", "/etc/hostname")
|
|
|
- out, _, err = runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to exec command: %v, output: %q", err, out)
|
|
|
- }
|
|
|
|
|
|
- cmd = exec.Command(dockerBinary, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname")
|
|
|
- out1, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatalf("failed to run container: %v, output: %q", err, out1)
|
|
|
- }
|
|
|
+ dockerCmd(c, "run", "-i", "-d", "--name", "parent", "busybox", "top")
|
|
|
+ out, _ := dockerCmd(c, "exec", "parent", "cat", "/etc/hostname")
|
|
|
+ out1, _ := dockerCmd(c, "run", "--net=container:parent", "busybox", "cat", "/etc/hostname")
|
|
|
+
|
|
|
if out1 != out {
|
|
|
c.Fatal("containers with shared net namespace should have same hostname")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func (s *DockerSuite) TestRunNetworkNotInitializedNoneMode(c *check.C) {
|
|
|
- cmd := exec.Command(dockerBinary, "run", "-d", "--net=none", "busybox", "top")
|
|
|
- out, _, err := runCommandWithOutput(cmd)
|
|
|
- if err != nil {
|
|
|
- c.Fatal(err)
|
|
|
- }
|
|
|
+ out, _, err := dockerCmdWithError(c, "run", "-d", "--net=none", "busybox", "top")
|
|
|
id := strings.TrimSpace(out)
|
|
|
res, err := inspectField(id, "NetworkSettings.IPAddress")
|
|
|
c.Assert(err, check.IsNil)
|