fix the problem that memory-swap=-1 is not working for docker command
| ... | ... |
@@ -60,6 +60,19 @@ func TestRunEchoStdoutWithMemoryLimit(t *testing.T) {
|
| 60 | 60 |
logDone("run - echo with memory limit")
|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
+// should run without memory swap |
|
| 64 |
+func TestRunWithoutMemoryswapLimit(t *testing.T) {
|
|
| 65 |
+ runCmd := exec.Command(dockerBinary, "run", "-m", "16m", "--memory-swap", "-1", "busybox", "true") |
|
| 66 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 67 |
+ if err != nil {
|
|
| 68 |
+ t.Fatalf("failed to run container, output: %q", out)
|
|
| 69 |
+ } |
|
| 70 |
+ |
|
| 71 |
+ deleteAllContainers() |
|
| 72 |
+ |
|
| 73 |
+ logDone("run - without memory swap limit")
|
|
| 74 |
+} |
|
| 75 |
+ |
|
| 63 | 76 |
// "test" should be printed |
| 64 | 77 |
func TestRunEchoStdoutWitCPULimit(t *testing.T) {
|
| 65 | 78 |
runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test") |
| ... | ... |
@@ -140,11 +140,15 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe |
| 140 | 140 |
|
| 141 | 141 |
var MemorySwap int64 |
| 142 | 142 |
if *flMemorySwap != "" {
|
| 143 |
- parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap) |
|
| 144 |
- if err != nil {
|
|
| 145 |
- return nil, nil, cmd, err |
|
| 143 |
+ if *flMemorySwap == "-1" {
|
|
| 144 |
+ MemorySwap = -1 |
|
| 145 |
+ } else {
|
|
| 146 |
+ parsedMemorySwap, err := units.RAMInBytes(*flMemorySwap) |
|
| 147 |
+ if err != nil {
|
|
| 148 |
+ return nil, nil, cmd, err |
|
| 149 |
+ } |
|
| 150 |
+ MemorySwap = parsedMemorySwap |
|
| 146 | 151 |
} |
| 147 |
- MemorySwap = parsedMemorySwap |
|
| 148 | 152 |
} |
| 149 | 153 |
|
| 150 | 154 |
var binds []string |