diff --git a/pkg/compose/start.go b/pkg/compose/start.go index bdf43f743..b116d1c43 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -115,7 +115,7 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string restarted := watched[container.ID] watched[container.ID] = restarted + 1 // Container terminated. - willRestart := inspected.HostConfig.RestartPolicy.MaximumRetryCount > restarted + willRestart := willContainerRestart(inspected, restarted) listener(api.ContainerEvent{ Type: api.ContainerEventExit, @@ -162,3 +162,14 @@ func (s *composeService) watchContainers(ctx context.Context, projectName string } 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 +}