Skip to content
Latchkey

GitHub Actions "service container is not healthy"

A service container defines a health check, but it never reaches a healthy state within the runner timeout, so the job is aborted at initialization. On Latchkey managed runners, transient service-startup failures are auto-retried and warm pools shorten the cold-start window that often causes flaky health checks.

What this error means

The "Initialize containers" phase fails reporting that a named service container is not healthy.

github-actions
##[error]Failed to initialize container postgres:16
Error: The container 'postgres' in your job is not healthy.

Common causes

Health check command is wrong

The configured health check probes a command or port the service does not expose yet, so it never passes.

Service needs more startup time

The default retries and interval expire before a slow service (database, search engine) finishes initializing.

Missing required environment

The service exits early because a required env var (for example a database password) was not provided.

How to fix it

Tune the health check and env

  1. Provide the service its required environment variables.
  2. Set a health check that matches how the service signals readiness, with generous retries and a start period.
  3. Re-run.
.github/workflows/ci.yml
services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_PASSWORD: postgres
    options: >-
      --health-cmd "pg_isready -U postgres"
      --health-interval 10s
      --health-timeout 5s
      --health-retries 10

How to prevent it

  • Always pass required env to service containers so they start cleanly.
  • Give slow services a start period and ample health retries.

Frequently asked questions

What causes ""container ... is not healthy""?
The configured health check probes a command or port the service does not expose yet, so it never passes.
How do I fix "container ... is not healthy"?
Tune the health check and env

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card