Docker Compose Validator
Validate your docker-compose.yml against the Compose spec, highlight errors, and visualise service relationships - ports, volumes, and depends_on - as a network diagram.
What does this Docker Compose Validator check?
This free online Docker Compose validator parses your docker-compose.yml file, checks it against the Compose specification, and highlights errors with plain-English descriptions. It also visualises service relationships - ports, exposed volumes, and depends_on chains - so you can understand the architecture at a glance. Paste your file to catch YAML syntax errors, undefined service references, incorrect port formats, and other common mistakes before running docker compose up.
Common Docker Compose mistakes
The most frequent errors are: YAML indentation errors - YAML is whitespace-sensitive and tabs are not allowed (use spaces only). Undefined service references in depends_on, networks, or volumes - if you reference a service that isn't defined under services:, Compose will error at startup. Port format errors - ports: - 8080:80 should be a string ("8080:80") to avoid YAML interpreting colons as key-value separators. Confusing expose and ports - expose makes ports available between services on the same network; ports also maps them to the host machine.
Frequently Asked Questions
What is the difference between expose and ports in Docker Compose?
expose documents which ports the container listens on, making them available to other services on the same Docker network - but not to the host machine. ports maps container ports to host ports (host:container), making the service accessible from outside Docker. For production, avoid publishing database ports (e.g., 3306) to the host unless needed for local development.
What does depends_on actually guarantee?
depends_on controls startup order, not readiness. Even with depends_on: db, your app container may start before MySQL is ready to accept connections. Use depends_on: condition: service_healthy with a healthcheck on the dependency service for true readiness gating.
What is the difference between environment and env_file?
environment: inlines key-value pairs directly in the Compose file - visible to anyone with access to the file. env_file: reads from an external .env file - better for secrets since the file can be gitignored. Both set environment variables in the running container, but env_file keeps secrets out of version control.
How do I validate docker-compose.yml from the command line?
Run docker compose config in the directory containing your docker-compose.yml. This validates the file and prints the resolved, merged configuration. Use docker compose config --quiet in CI pipelines to fail on errors without printing the full config.