diff --git a/daemon/update.go b/daemon/update.go index 67c0e59bf1..6e26eeb96a 100644 --- a/daemon/update.go +++ b/daemon/update.go @@ -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. diff --git a/integration-cli/docker_cli_update_unix_test.go b/integration-cli/docker_cli_update_unix_test.go index fb695372f1..580ff02602 100644 --- a/integration-cli/docker_cli_update_unix_test.go +++ b/integration-cli/docker_cli_update_unix_test.go @@ -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) +}