1
0
Эх сурвалжийг харах

better detect container will restart

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 4 жил өмнө
parent
commit
ed2395819d
1 өөрчлөгдсөн 12 нэмэгдсэн , 1 устгасан
  1. 12 1
      pkg/compose/start.go

+ 12 - 1
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
+}