@@ -31,6 +31,7 @@ import (
31
31
"github.com/docker/docker/api/types/filters"
32
32
"github.com/docker/docker/api/types/network"
33
33
specs "github.com/opencontainers/image-spec/specs-go/v1"
34
+ "github.com/pkg/errors"
34
35
"github.com/sirupsen/logrus"
35
36
"golang.org/x/sync/errgroup"
36
37
@@ -277,7 +278,7 @@ func containerEvents(containers Containers, eventFunc func(string) progress.Even
277
278
return events
278
279
}
279
280
280
- // ServiceConditionRunningOrHealthy is a service condition on statys running or healthy
281
+ // ServiceConditionRunningOrHealthy is a service condition on status running or healthy
281
282
const ServiceConditionRunningOrHealthy = "running_or_healthy"
282
283
283
284
func (s * composeService ) waitDependencies (ctx context.Context , project * types.Project , dependencies types.DependsOnConfig ) error {
@@ -315,7 +316,8 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr
315
316
case types .ServiceConditionHealthy :
316
317
healthy , err := s .isServiceHealthy (ctx , project , dep , false )
317
318
if err != nil {
318
- return err
319
+ w .Events (containerEvents (containers , progress .ErrorEvent ))
320
+ return errors .Wrap (err , "dependency failed to start" )
319
321
}
320
322
if healthy {
321
323
w .Events (containerEvents (containers , progress .Healthy ))
@@ -644,7 +646,7 @@ func (s *composeService) connectContainerToNetwork(ctx context.Context, id strin
644
646
}
645
647
646
648
func (s * composeService ) isServiceHealthy (ctx context.Context , project * types.Project , service string , fallbackRunning bool ) (bool , error ) {
647
- containers , err := s .getContainers (ctx , project .Name , oneOffExclude , false , service )
649
+ containers , err := s .getContainers (ctx , project .Name , oneOffExclude , true , service )
648
650
if err != nil {
649
651
return false , err
650
652
}
@@ -662,6 +664,10 @@ func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Pr
662
664
return container .State != nil && container .State .Status == "running" , nil
663
665
}
664
666
667
+ if container .State .Status == "exited" {
668
+ return false , fmt .Errorf ("container for service %q exited (%d)" , service , container .State .ExitCode )
669
+ }
670
+
665
671
if container .State == nil || container .State .Health == nil {
666
672
return false , fmt .Errorf ("container for service %q has no healthcheck configured" , service )
667
673
}
0 commit comments