Validating docker-compose yml file

DockerDocker Compose

Docker Problem Overview


Is there any easy way to verify the syntax, etc of a docker-compose file (docker-compose.yml aka fig.yml) without having to run docker proper?

I am trying to add a quick check to my build / test pipeline to verify my compose files.

Docker Solutions


Solution 1 - Docker

Meanwhile this has been added to docker-compose as docker-compose config. Validating your file now is as simple as docker-compose -f docker-compose.yml config. As always, you can omit the -f docker-compose.yml part when running this in the same folder as the file itself or having the COMPOSE_FILE environment variable pointing to your file.

Solution 2 - Docker

Use pre-commit framework https://pre-commit.com/#usage and this hook https://github.com/IamTheFij/docker-pre-commit.

Install pre-commit and add these lines to .pre-commit-config.yaml:

repos:
  # Docker hooks
  - repo: https://github.com/IamTheFij/docker-pre-commit
    rev: v2.0.0
    hooks:
      - id: docker-compose-check

Then run precommit run --all-files.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex RothbergView Question on Stackoverflow
Solution 1 - DockerDirkView Answer on Stackoverflow
Solution 2 - DockerharuhiView Answer on Stackoverflow