How to fix ERROR: for app Container depends_on condition on db is invalid in Docker

DockerINTERMEDIATELOWUpdated Dec 6, 2025· 212 views

This error occurs when using the condition syntax with depends_on in Docker Compose. It typically happens because Compose version 3 removed support for conditions, but modern Docker Compose (v2+) has restored this feature under the Compose Specification.

Quick fix

Fixes ERROR: for app Container depends_on condition on db is invalid

# Remove this line or update to a higher version
# version: "3"  # <-- Delete this

services:
  web:
    build: .
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
  1. Remove or update the version field (Recommended)
  2. Use docker compose (v2) instead of docker-compose (v1)
  3. Add healthcheck to dependency service
  4. Use version 2.4 if you need legacy compatibility
docker — error
# Remove this line or update to a higher version
# version: "3" # <-- Delete this
services:
web:
build: .
depends_on:
db:
condition: service_healthy
db:
image: postgres:15
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
ERROR: for app Container depends_on condition on db is invalid

What this error means

The "depends_on condition is invalid" error appears when Docker Compose cannot parse your depends_on configuration with a condition attribute. This usually happens because you're using an older version of Docker Compose CLI or a Compose file format that doesn't support the extended depends_on syntax. When Docker Compose v3 was released, it intentionally removed the `condition` form of `depends_on` to target Docker Swarm deployments. However, starting with Docker Compose v1.27.0, the 2.x and 3.x specifications were merged under the Compose Specification, and the condition syntax was restored for standalone Docker Compose usage. The confusion arises because the `version` field in your docker-compose.yml determines which syntax is valid. If you specify `version: "3"` or similar, Docker Compose may reject the condition syntax depending on your CLI version.

Typical symptoms

  • Running 'docker-compose up' fails with 'depends_on condition is invalid'
  • Error message mentions 'invalid type, should be an array'
  • The same docker-compose.yml file works on some machines but not others
  • Adding 'condition: service_healthy' to depends_on causes the error
  • Error appears after upgrading Docker Compose or changing the version field

Common causes

  1. Using 'version: 3' or 'version: 3.x' which historically removed condition support
  2. Running old docker-compose (v1) CLI instead of modern docker compose (v2)
  3. Dependency service lacks a healthcheck when using service_healthy condition
  4. Incorrect YAML syntax in the depends_on block
  5. Docker Desktop or Docker Engine version doesn't support Compose Specification

How to fix "ERROR: for app Container depends_on condition on db is invalid"

1Remove or update the version field (Recommended)

The simplest fix is to remove the version field entirely. Modern Docker Compose (v2+) uses the Compose Specification which supports conditions by default:

yaml
# Remove this line or update to a higher version
# version: "3"  # <-- Delete this

services:
  web:
    build: .
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

When the version field is omitted, Docker Compose uses the Compose Specification schema which fully supports the condition syntax.

2Use docker compose (v2) instead of docker-compose (v1)

Make sure you're using the modern Docker Compose CLI. The newer version is a Docker plugin and uses a space instead of a hyphen:

bash
# Check your version
docker compose version   # Modern v2 (plugin)
docker-compose version   # Legacy v1 (standalone)

# Use the modern command
docker compose up        # ✅ Use this
docker-compose up        # ❌ Avoid if possible

If you only have docker-compose (with hyphen), install the Docker Compose plugin:

bash
# On Ubuntu/Debian
sudo apt-get update
sudo apt-get install docker-compose-plugin

# Or via Docker Desktop (includes it by default)
3Add healthcheck to dependency service

If you're using condition: service_healthy, the dependency service must define a healthcheck. Without it, Docker Compose cannot determine when the service is "healthy":

yaml
services:
  app:
    build: .
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s

  redis:
    image: redis:7
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

Common healthcheck commands:
- PostgreSQL: pg_isready -U <user>
- MySQL: mysqladmin ping -h localhost
- Redis: redis-cli ping
- Generic HTTP: curl -f http://localhost:8080/health

4Use version 2.4 if you need legacy compatibility

If you cannot upgrade to Docker Compose v2 and must use the legacy CLI, use version 2.4 which supports the condition syntax:

yaml
version: "2.4"

services:
  app:
    build: .
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5

Note: Version 2.x files don't support Swarm mode features like deploy, but they provide full depends_on condition support.

5Verify correct YAML syntax

Ensure your depends_on uses the correct long-form syntax with proper indentation:

yaml
# ❌ WRONG - Array syntax (no conditions)
depends_on:
  - db
  - redis

# ❌ WRONG - Incorrect nesting
depends_on:
  db:
  condition: service_healthy

# ✅ CORRECT - Long-form syntax
depends_on:
  db:
    condition: service_healthy
  redis:
    condition: service_started

Available conditions:
- service_started - Wait for container to start (default)
- service_healthy - Wait for healthcheck to pass
- service_completed_successfully - Wait for container to exit with code 0

Advanced notes

Understanding Compose versioning history: Docker Compose v3 was designed for Swarm compatibility and intentionally removed the condition syntax because Swarm handles orchestration differently. The Compose Specification (post v1.27.0) reunified the syntax, making conditions available again for standalone Docker Compose usage.

Using `restart: true` with depends_on: In the Compose Specification, you can also use restart: true to automatically restart a service when its dependency is restarted:

yaml
depends_on:
  db:
    condition: service_healthy
    restart: true

The `required` option: Set required: false to make a dependency optional (service starts even if dependency fails):

yaml
depends_on:
  cache:
    condition: service_healthy
    required: false

Wait scripts as an alternative: If you're stuck on old infrastructure, consider using wait scripts like wait-for-it.sh, dockerize, or wait-for:

yaml
services:
  app:
    command: ["./wait-for-it.sh", "db:5432", "--", "npm", "start"]
    depends_on:
      - db

CI/CD considerations: In CI environments, ensure the Docker Compose version matches your local development. Pin specific versions in your CI configuration to avoid version-related failures.

Frequently asked questions

What does "ERROR: for app Container depends_on condition on db is invalid" mean?
The "depends_on condition is invalid" error appears when Docker Compose cannot parse your depends_on configuration with a condition attribute. This usually happens because you're using an older version of Docker Compose CLI or a Compose file format that doesn't support the extended depends_on syntax. When Docker Compose v3 was released, it intentionally removed the condition form of depends_on to target Docker Swarm deployments.
How do I fix "ERROR: for app Container depends_on condition on db is invalid"?
This error occurs when using the condition syntax with depends_on in Docker Compose. It typically happens because Compose version 3 removed support for conditions, but modern Docker Compose (v2+) has restored this feature under the Compose Specification.
What causes "ERROR: for app Container depends_on condition on db is invalid"?
Using 'version: 3' or 'version: 3.x' which historically removed condition support Running old docker-compose (v1) CLI instead of modern docker compose (v2) Dependency service lacks a healthcheck when using service_healthy condition
Is the "ERROR: for app Container depends_on condition on db is invalid" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading