mirror of https://github.com/docker/compose.git
better detect container will restart
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
e6599c7213
commit
ed2395819d
|
@ -115,7 +115,7 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string
|
||||||
restarted := watched[container.ID]
|
restarted := watched[container.ID]
|
||||||
watched[container.ID] = restarted + 1
|
watched[container.ID] = restarted + 1
|
||||||
// Container terminated.
|
// Container terminated.
|
||||||
willRestart := inspected.HostConfig.RestartPolicy.MaximumRetryCount > restarted
|
willRestart := willContainerRestart(inspected, restarted)
|
||||||
|
|
||||||
listener(api.ContainerEvent{
|
listener(api.ContainerEvent{
|
||||||
Type: api.ContainerEventExit,
|
Type: api.ContainerEventExit,
|
||||||
|
@ -162,3 +162,14 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func willContainerRestart(container moby.ContainerJSON, restarted int) bool {
|
||||||
|
policy := container.HostConfig.RestartPolicy
|
||||||
|
if policy.IsAlways() || policy.IsUnlessStopped() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if policy.IsOnFailure() {
|
||||||
|
return container.State.ExitCode != 0 && policy.MaximumRetryCount > restarted
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue