Forráskód Böngészése

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 <leijitang@huawei.com>
Lei Jitang 9 éve
szülő
commit
518ed75e1a

+ 1 - 1
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.
 	// the command so we can update configs to the real world.
 	if container.IsRunning() {
 	if container.IsRunning() {
 		container.Lock()
 		container.Lock()
-		updateCommand(container.Command, resources)
+		updateCommand(container.Command, *cResources)
 		container.Unlock()
 		container.Unlock()
 	}
 	}
 
 

+ 34 - 0
integration-cli/docker_cli_update_unix_test.go

@@ -3,8 +3,11 @@
 package main
 package main
 
 
 import (
 import (
+	"encoding/json"
+	"fmt"
 	"strings"
 	"strings"
 
 
+	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/docker/docker/pkg/integration/checker"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
 )
 )
@@ -160,3 +163,34 @@ func (s *DockerSuite) TestUpdateKernelMemory(c *check.C) {
 	out, _ = dockerCmd(c, "exec", name, "cat", file)
 	out, _ = dockerCmd(c, "exec", name, "cat", file)
 	c.Assert(strings.TrimSpace(out), checker.Equals, "104857600")
 	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)
+
+}