Fix update clear the restart policy of monitor

Signed-off-by: Lei Jitang <leijitang@huawei.com>
(cherry picked from commit 737b5b1781)
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Lei Jitang 2016-12-16 20:57:05 -05:00 committed by Vincent Demeester
parent 4e9dd0e51c
commit a46dbbded9
2 changed files with 34 additions and 1 deletions

View File

@ -67,7 +67,9 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
}
// if Restart Policy changed, we need to update container monitor
container.UpdateMonitor(hostConfig.RestartPolicy)
if hostConfig.RestartPolicy.Name != "" {
container.UpdateMonitor(hostConfig.RestartPolicy)
}
// If container is not running, update hostConfig struct is enough,
// resources will be updated when the container is started again.

View File

@ -5,7 +5,10 @@ package main
import (
"encoding/json"
"fmt"
"github.com/kr/pty"
"os/exec"
"strings"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/integration/checker"
@ -250,3 +253,31 @@ func (s *DockerSuite) TestUpdateMemoryWithSwapMemory(c *check.C) {
dockerCmd(c, "update", "--memory", "800M", "--memory-swap", "1000M", name)
}
func (s *DockerSuite) TestUpdateNotAffectMonitorRestartPolicy(c *check.C) {
testRequires(c, DaemonIsLinux, cpuShare)
out, _ := dockerCmd(c, "run", "-tid", "--restart=always", "busybox", "sh")
id := strings.TrimSpace(string(out))
dockerCmd(c, "update", "--cpu-shares", "512", id)
cpty, tty, err := pty.Open()
c.Assert(err, checker.IsNil)
defer cpty.Close()
cmd := exec.Command(dockerBinary, "attach", id)
cmd.Stdin = tty
c.Assert(cmd.Start(), checker.IsNil)
defer cmd.Process.Kill()
_, err = cpty.Write([]byte("exit\n"))
c.Assert(err, checker.IsNil)
c.Assert(cmd.Wait(), checker.IsNil)
// container should restart again and keep running
err = waitInspect(id, "{{.RestartCount}}", "1", 30*time.Second)
c.Assert(err, checker.IsNil)
c.Assert(waitRun(id), checker.IsNil)
}