The yamllint is a command line tool used to check YAML files for syntax errors, formatting issues, and best practices. It helps ensure that YAML files are well-formed and follow consistent styling rules.
This tutorial explains how to run yamllint inside Docker container on Linux. Commands have been tested on Ubuntu.
First, we need a sample YAML project to work with. You can clone the following GitHub repository that contains YAML files:
git clone https://github.com/eazybytes/yaml && cd yaml
This will download the repository and navigate into the project directory.
Instead of installing yamllint manually, we can use a pre-built Docker image. Run the following command inside the project directory:
docker run -it --rm -v ./:/code pipelinecomponents/yamllint yamllint .
Explanation of the command:
docker run
- runs a new container.-it
- starts an interactive terminal session.--rm
- removes the container after execution to keep things clean.-v ./:/code
- mounts the current directory (./
) into the container at/code
. This allows yamllint inside the container to access the local files.pipelinecomponents/yamllint
- specifies the Docker image to use.yamllint .
- runs yamllint against all YAML files in the current directory.
After running the command, yamllint will analyze the YAML files and output any warnings or errors. A sample output might look like this:
./07_collections/collections.yml
2:1 warning missing document start "---" (document-start)
39:17 error no new line character at the end of file (new-line-at-end-of-file)
You can customize the linting rules by creating a .yamllint.yaml
configuration file in the project root. Here's a simple example:
extends: default
rules:
document-start: disable
Then, run yamllint again using the same Docker command to apply the new rules.
Leave a Comment
Cancel reply