验证 docker-撰写 yml 文件

有没有什么简单的方法可以验证一个 docker-compose 文件(docker-compose.yml aka fig.yml)的语法等,而不必正确地运行 docker?

我正在尝试向构建/测试管道添加一个快速检查,以验证我的撰写文件。

92901 次浏览

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.

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 pre-commit run --all-files.