Add support for setting sysctls
This patch will allow users to specify namespace specific "kernel parameters" for running inside of a container. Signed-off-by: Dan Walsh <dwalsh@redhat.com> Upstream-commit: 9caf7aeefd23263a209c26c8439d26c147972d81 Component: engine
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user