Allow setting ulimits for containers

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 3f39050637d454e9ee8075153a917c8bfccb5bae
Component: engine
This commit is contained in:
Brian Goff
2015-02-25 19:37:43 -05:00
parent 71c9fa9fcf
commit 2e0ec2c817
16 changed files with 365 additions and 10 deletions
@@ -480,3 +480,56 @@ func TestDaemonUpgradeWithVolumes(t *testing.T) {
logDone("daemon - volumes from old(pre 1.3) daemon work")
}
func TestDaemonUlimitDefaults(t *testing.T) {
d := NewDaemon(t)
if err := d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"); err != nil {
t.Fatal(err)
}
out, err := d.Cmd("run", "--ulimit", "nproc=2048", "--name=test", "busybox", "/bin/sh", "-c", "echo $(ulimit -n); echo $(ulimit -p)")
if err != nil {
t.Fatal(out, err)
}
outArr := strings.Split(out, "\n")
if len(outArr) < 2 {
t.Fatal("got unexpected output: %s", out)
}
nofile := strings.TrimSpace(outArr[0])
nproc := strings.TrimSpace(outArr[1])
if nofile != "42" {
t.Fatalf("expected `ulimit -n` to be `42`, got: %s", nofile)
}
if nproc != "2048" {
t.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
}
// Now restart daemon with a new default
if err := d.Restart("--default-ulimit", "nofile=43"); err != nil {
t.Fatal(err)
}
out, err = d.Cmd("start", "-a", "test")
if err != nil {
t.Fatal(err)
}
outArr = strings.Split(out, "\n")
if len(outArr) < 2 {
t.Fatal("got unexpected output: %s", out)
}
nofile = strings.TrimSpace(outArr[0])
nproc = strings.TrimSpace(outArr[1])
if nofile != "43" {
t.Fatalf("expected `ulimit -n` to be `43`, got: %s", nofile)
}
if nproc != "2048" {
t.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc)
}
logDone("daemon - default ulimits are applied")
}
@@ -91,3 +91,18 @@ func TestRunWithVolumesIsRecursive(t *testing.T) {
logDone("run - volumes are bind mounted recursively")
}
func TestRunWithUlimits(t *testing.T) {
defer deleteAllContainers()
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name=testulimits", "--ulimit", "nofile=42", "busybox", "/bin/sh", "-c", "ulimit -n"))
if err != nil {
t.Fatal(err, out)
}
ul := strings.TrimSpace(out)
if ul != "42" {
t.Fatalf("expected `ulimit -n` to be 42, got %s", ul)
}
logDone("run - ulimits are set")
}