diff --git a/libpod/container_api.go b/libpod/container_api.go index 4168b1d7cc..52b7e145de 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -781,6 +781,14 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou } } if len(wantedHealthStates) > 0 { + // even if we are interested only in the health check + // check that the container is still running to avoid + // waiting until the timeout expires. + state, err := c.State() + if err != nil { + trySend(-1, err) + return + } status, err := c.HealthCheckStatus() if err != nil { trySend(-1, err) @@ -790,6 +798,10 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou trySend(-1, nil) return } + if state != define.ContainerStateCreated && state != define.ContainerStateRunning && state != define.ContainerStatePaused { + trySend(-1, define.ErrCtrStopped) + return + } } select { case <-ctx.Done():