Tutorial · Compose Validator · 4 min read

How to Validate a Docker Compose File

Check docker-compose.yml for YAML errors and the mistakes that stop a stack from starting: no image or build, unquoted ports, missing restart policy.

docker compose up fails late and loudly. A quick validation first catches the usual suspects: a service with neither image nor build, a port written as 8080:80 without quotes so YAML reads it as a number, a volume path typo, a tab in the indentation.

What you'll learn

  • Verify every service has an image or a build context
  • Write ports and volumes in the forms Compose accepts
  • Add restart policies and pinned image tags before deploying

Step by step

  1. Paste the compose file

    Open the Docker Compose Validator and paste docker-compose.yml. Try an example loads a stack with a deliberate mistake.

  2. Click Validate

    Errors are things Compose will refuse; warnings and info are things that will bite you later.

    services:
      web:
        ports: ["8080:80"]      → ERROR web has neither image nor build
      db:
        image: postgres          → WARNING no tag, pin a version
                                 → INFO  no restart policy
  3. Fix and re-check

    Add image: or build:, quote port strings, pin tags, and add restart: unless-stopped for long-running services.

  4. Confirm with Compose itself

    Run docker compose config locally. It resolves variables and prints the effective file, the last check before up.

Open the tool with this example Runs in your browser. Nothing you paste is uploaded.

Common problems

Service has neither image nor build

Compose needs to know what to run. Add image: name:tag to pull, or build: ./path to build from a Dockerfile.

Port mapping looks wrong

Write ports as quoted strings, "8080:80". Unquoted, YAML may parse 8080:80 as a base-60 number.

YAML error on a line that looks fine

Check for a tab character; YAML only accepts spaces for indentation.

FAQ

Does it check environment variable substitution?

No. ${VAR} references are left as text; docker compose config resolves them.