Skip to main content

CV-M010: depends_on service_healthy without healthcheck

Error Semantic

Why This Matters

A service uses depends_on with condition: service_healthy, but the target service does not define a healthcheck. Docker Compose will wait indefinitely for the target to become healthy, effectively hanging the startup. Either add a healthcheck to the target service or change the condition to service_started.

How to Fix

Add a healthcheck to the target service or use service_started condition.

Before (incorrect)

services:
  web:
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres

After (correct)

services:
  web:
    depends_on:
      db:
        condition: service_healthy
  db:
    image: postgres
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5

Rule Details

Rule Code
CV-M010
Severity
Error
Category
Semantic

Related Rules