|
@@ -4,6 +4,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"bufio"
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"os"
|
|
@@ -747,6 +748,37 @@ func (s *DockerSuite) TestRunTmpfsMounts(c *check.C) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (s *DockerSuite) TestRunSysctls(c *check.C) {
|
|
|
+
|
|
|
+ testRequires(c, DaemonIsLinux)
|
|
|
+ var err error
|
|
|
+
|
|
|
+ out, _ := dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=1", "--name", "test", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
|
|
|
+ c.Assert(strings.TrimSpace(out), check.Equals, "1")
|
|
|
+
|
|
|
+ out = inspectFieldJSON(c, "test", "HostConfig.Sysctls")
|
|
|
+
|
|
|
+ sysctls := make(map[string]string)
|
|
|
+ err = json.Unmarshal([]byte(out), &sysctls)
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
+ c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "1")
|
|
|
+
|
|
|
+ out, _ = dockerCmd(c, "run", "--sysctl", "net.ipv4.ip_forward=0", "--name", "test1", "busybox", "cat", "/proc/sys/net/ipv4/ip_forward")
|
|
|
+ c.Assert(strings.TrimSpace(out), check.Equals, "0")
|
|
|
+
|
|
|
+ out = inspectFieldJSON(c, "test1", "HostConfig.Sysctls")
|
|
|
+
|
|
|
+ err = json.Unmarshal([]byte(out), &sysctls)
|
|
|
+ c.Assert(err, check.IsNil)
|
|
|
+ c.Assert(sysctls["net.ipv4.ip_forward"], check.Equals, "0")
|
|
|
+
|
|
|
+ runCmd := exec.Command(dockerBinary, "run", "--sysctl", "kernel.foobar=1", "--name", "test2", "busybox", "cat", "/proc/sys/kernel/foobar")
|
|
|
+ out, _, _ = runCommandWithOutput(runCmd)
|
|
|
+ if !strings.Contains(out, "invalid value") {
|
|
|
+ c.Fatalf("expected --sysctl to fail, got %s", out)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// TestRunSeccompProfileDenyUnshare checks that 'docker run --security-opt seccomp=/tmp/profile.json debian:jessie unshare' exits with operation not permitted.
|
|
|
func (s *DockerSuite) TestRunSeccompProfileDenyUnshare(c *check.C) {
|
|
|
testRequires(c, SameHostDaemon, seccompEnabled, NotArm, Apparmor)
|