From aee28e0e87385de153e60e21c314032892b350f2 Mon Sep 17 00:00:00 2001 From: Qiang Huang Date: Mon, 9 Feb 2015 10:36:49 +0800 Subject: [PATCH] fix the problem that memory-swap=-1 is not working for docker command Signed-off-by: Qiang Huang --- integration-cli/docker_cli_run_test.go | 13 +++++++++++++ runconfig/parse.go | 12 ++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index c66ea27450..879083c867 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -60,6 +60,19 @@ func TestRunEchoStdoutWithMemoryLimit(t *testing.T) { logDone("run - echo with memory limit") } +// should run without memory swap +func TestRunWithoutMemoryswapLimit(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true") + out, _, err := runCommandWithOutput(runCmd) + if err != nil { + t.Fatalf("failed to run container, output: %q", out) + } + + deleteAllContainers() + + logDone("run - without memory swap limit") +} + // "test" should be printed func TestRunEchoStdoutWitCPULimit(t *testing.T) { runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test") diff --git a/runconfig/parse.go b/runconfig/parse.go index 2d22ee2799..1455cdce3d 100644 --- a/runconfig/parse.go +++ b/runconfig/parse.go @@ -140,11 +140,15 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe var MemorySwap int64 if *flMemorySwap != "" { - parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap) - if err != nil { - return nil, nil, cmd, err + if *flMemorySwap == "-1" { + MemorySwap = -1 + } else { + parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap) + if err != nil { + return nil, nil, cmd, err + } + MemorySwap = parsedMemorySwap } - MemorySwap = parsedMemorySwap } var binds []string