Validating docker-compose yml file
DockerDocker ComposeDocker 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
.