mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Ensure all the running containers are killed on daemon shutdown
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
b50e780925
commit
bdb77078b5
2 changed files with 19 additions and 2 deletions
|
@ -1003,8 +1003,9 @@ func (daemon *Daemon) Shutdown() error {
|
|||
|
||||
go func() {
|
||||
defer group.Done()
|
||||
if err := c.KillSig(15); err != nil {
|
||||
logrus.Debugf("kill 15 error for %s - %s", c.ID, err)
|
||||
// If container failed to exit in 10 seconds of SIGTERM, then using the force
|
||||
if err := c.Stop(10); err != nil {
|
||||
logrus.Errorf("Stop container %s with error: %v", c.ID, err)
|
||||
}
|
||||
c.WaitStop(-1 * time.Second)
|
||||
logrus.Debugf("container stopped %s", c.ID)
|
||||
|
|
|
@ -1165,3 +1165,19 @@ func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
|
|||
c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
|
||||
check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
|
||||
if err := s.d.StartWithBusybox(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox"); err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
if err := s.d.Restart(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Container 'test' should be removed without error
|
||||
if out, err := s.d.Cmd("rm", "test"); err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue