From 518ed75e1ab5b102fffd7fcbf046c127b44c7be7 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Tue, 29 Dec 2015 20:33:16 -0500 Subject: [PATCH] Fix docker stats show wrong memory limit when do docker update When a container create with -m 100m and then docker update other cgroup settings such as --cpu-quota, the memory limit show by docker stats will become the default value but not the 100m. Signed-off-by: Lei Jitang --- container/container_unix.go | 2 +- .../docker_cli_update_unix_test.go | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/container/container_unix.go b/container/container_unix.go index 89f21fe440..0c3011d004 100644 --- a/container/container_unix.go +++ b/container/container_unix.go @@ -601,7 +601,7 @@ func (container *Container) UpdateContainer(hostConfig *container.HostConfig) er // the command so we can update configs to the real world. if container.IsRunning() { container.Lock() - updateCommand(container.Command, resources) + updateCommand(container.Command, *cResources) container.Unlock() } diff --git a/integration-cli/docker_cli_update_unix_test.go b/integration-cli/docker_cli_update_unix_test.go index ff9eb4daa1..cb1cfee892 100644 --- a/integration-cli/docker_cli_update_unix_test.go +++ b/integration-cli/docker_cli_update_unix_test.go @@ -3,8 +3,11 @@ package main import ( + "encoding/json" + "fmt" "strings" + "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/integration/checker" "github.com/go-check/check" ) @@ -160,3 +163,34 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) { out, _ = dockerCmd(c, "exec", name, "cat", file) c.Assert(strings.TrimSpace(out), checker.Equals, "104857600") } + +func (s *DockerSuite) TestUpdateStats(c *check.C) { + testRequires(c, DaemonIsLinux) + testRequires(c, memoryLimitSupport) + testRequires(c, cpuCfsQuota) + name := "foo" + dockerCmd(c, "run", "-d", "-ti", "--name", name, "-m", "500m", "busybox") + + c.Assert(waitRun(name), checker.IsNil) + + getMemLimit := func(id string) uint64 { + resp, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/stats?stream=false", id), nil, "") + c.Assert(err, checker.IsNil) + c.Assert(resp.Header.Get("Content-Type"), checker.Equals, "application/json") + + var v *types.Stats + err = json.NewDecoder(body).Decode(&v) + c.Assert(err, checker.IsNil) + body.Close() + + return v.MemoryStats.Limit + } + preMemLimit := getMemLimit(name) + + dockerCmd(c, "update", "--cpu-quota", "2000", name) + + curMemLimit := getMemLimit(name) + + c.Assert(preMemLimit, checker.Equals, curMemLimit) + +}