Merge pull request #29441 from coolljt0725/fix_update_restart_policy

Fix docker update clear restart policy of monitor
This commit is contained in:
Vincent Demeester 2016-12-19 10:30:04 +01:00 committed by GitHub
commit 0f68ecd3f7
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)
}