Docker Compose validator

Check a docker-compose.yml against the official Compose Specification schema, with the line of every problem, a fix for each one and the

loading Docker Compose validator
About this tool

What does a Docker Compose validator check?

A compose file can be valid YAML and still be wrong. A key with a typo, mem_limt instead of mem_limit, is silently a mistake. A service that depends on one that does not exist, a volume nobody declared, two services publishing the same host port, a restart value that Docker does not know: Compose finds these only when you run docker compose up, and sometimes only half way through. This validator checks the file before you run anything.

It does two kinds of checks. First, it validates the file against the official Compose Specification schema, which is built into the page, so every unknown key, wrong type or bad value is reported with its line and column. When a key looks like a typo of a valid one, the tool suggests the right name. Second, it checks the references that a schema cannot see: depends_on and links that point to missing services, volumes, networks, secrets and configs that are used but not declared, duplicate container_name values, duplicate host ports, ports outside 1 to 65535, network_mode together with networks, privileged mode, images without a tag or with latest, and declarations that nothing uses.

Each finding has a severity: error, warning or tip. Errors are things Compose will refuse or that cannot work. Warnings are risky. Tips are about habits, such as an obsolete version key. Every finding comes with a plain explanation and, where there is one, a fix. The check runs in your browser. The schema is built into the page, so nothing is uploaded and no file is fetched. When the file is clean, convert it with the Docker Compose to docker run converter or the Docker to Kubernetes converter.

How to validate a docker-compose.yml

  1. Paste your docker-compose.yml or compose.yaml in the box. It opens with an example that has several mistakes, so you can see how the report looks.
  2. The result appears as you type. The status line says Valid file, or the number of errors, with the number of warnings and tips next to it.
  3. Read the findings. Each row shows the line and column, a severity, a code, the explanation and the fix. Fix them from the top, because one mistake can hide or cause the next.
  4. When there is nothing left, the result says: No problems found. The file follows the Compose Specification.
  5. Copy the report if you want to paste it in an issue or a pull request.

The file is never changed. If you want to tidy the layout afterwards, use the YAML formatter.

Examples

The default example

The example file has a web service with several mistakes, and a database with a typo:

services:
  web:
    image: nginx
    ports:
      - "8080:80"
      - "8080:8080"
    depends_on:
      - cache
    restart: sometimes
    mem_limt: 512m
    volumes:
      - data:/usr/share/nginx/html
  db:
    imgae: postgres:16
    environment:
      POSTGRES_PASSWORD: example
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 5

The report, as you get it when you copy it, has 7 errors and 1 tip:

3:5 info imageNoTag Image nginx has no tag, so it means latest. A later pull may change what runs.
7:5 error dependsOnMissing Service web depends on cache, which is not defined in this file.
9:5 error restartValue Service web has restart sometimes, which is not a restart policy.
10:5 error schema-unknownKeySuggest services.web.mem_limt: mem_limt is not a valid key here. Did you mean mem_limit?
11:5 error undeclared Service web uses the volume data, which is not declared in the top-level section.
13:3 error noImageOrBuild Service db has neither image nor build, so Compose does not know what to run.
14:5 error schema-unknownKeySuggest services.db.imgae: imgae is not a valid key here. Did you mean image?
19:7 error schema-type services.db.healthcheck.interval: expected string, found integer.

In the page, each line is followed by its fix. For the interval, write a string such as 5s, not a bare number.

A valid file with tips

version: "3.8"
services:
  api:
    image: ghcr.io/acme/api:1.2
    ports: ["3000:3000"]
    networks: [back]
networks:
  back:
  unused:

The status shows Valid file and 2 tips. At line 1: "The version key is obsolete. Compose ignores it and prints a warning." Fix: delete the line. At line 9: "Network unused is declared but no service uses it."

Conflicts between services

services:
  a:
    image: x:1
    ports: ["8080:80"]
  b:
    image: y:1
    ports: ["8080:81"]
    privileged: true
    network_mode: host
    networks: [n]
networks:
  n:

The validator reports an error at line 5, "Service b sets both network_mode and networks. Compose accepts only one of them.", and two warnings: "Service b publishes host port 8080/tcp, which a already publishes. Only one can bind it." (line 7) and "Service b runs privileged: it has almost the same access as the host." (line 8).

Quotes in the list form

In environment, the list form keeps quotes as part of the value. For - A="b c" the tool warns: "Service a: the entry A="b c" keeps its quotes as part of the value in the list form." Write - A=b c without quotes, or use the mapping form A: b c.

Common errors and how to fix them

  • This is not valid YAML: the message says why and the report gives the line. Use spaces and not tabs ("Tabs are not allowed as indentation"), close the quotes and do not write a key twice.
  • A compose file is a YAML map with a services section: the text is a list or a single value. Start with services:.
  • No services found: add a services section with at least one service.
  • This file uses the old version 1 layout: services are at the top level. Add services: at the top and indent them under it.
  • {property} is not a valid key here: a typo or a key in the wrong place. If the tool says "Did you mean", use that name.
  • expected string, found integer: a value has the wrong type. Durations such as interval are strings like 10s.
  • depends on X, which is not defined in this file: add the service, fix the name, or remove it from depends_on.
  • uses the volume X, which is not declared: declare it under the top-level volumes:, or use a path that starts with ./ for a folder.
  • publishes port 99999, outside 1 to 65535: use a valid port. The random port generator draws a free one.

Frequently asked questions

How do I validate a docker-compose.yml?

Paste it and read the report. An empty list of errors and the label Valid file mean the file follows the Compose Specification and its references agree with each other.

Does a valid file always start?

No. The validator checks structure and references, not your images, networks or the ports already used on your machine. It catches mistakes early, but docker compose config and a real start remain the final test.

Why is the version key flagged?

Modern Compose ignores version and prints a warning. It is a tip, not an error. Delete the line.

Is my file uploaded?

No. The schema is built into the page and the check runs in your browser.

How to run the result

Bash

docker compose config -q     # validate with Compose itself, silent when fine
docker compose config        # print the file with everything resolved
docker compose up -d         # start the stack
Report a problem