Some times ago, we started a new project at work and we wanted to add a GitLab CI pipeline for continuous integration.
As we were using Docker, we wanted to lint our Dockerfile automatically to make sure we were following best practices. We therefore sought to add a tool that we were using in other projects: hadolint.
What is hadolint?
hadolint is a linter that helps us build better Docker images. It uses your Dockerfiles to check over 50 rules and can even validate your Bash commandes with ShellCheck. π
You can check at their GitHub repository to find an (incomplete) list of implemented rules. Rules prefixed by DL
come from hadolint and rules prefixed by SC
come from ShellCheck.
How to add it to your .gitlab-ci.yml file?
As I was looking to see if any new features were been added since the last time I checked, I was pleasantly surprised to see that the maintainers and contributors added a new way to use the tool by providing the recipe to use in GitLab:
Personally, I found this way cleaner than running the docker run --rm -i hadolint/hadolint < Dockerfile
command, so I decide to write this little post to celebrate this new functionality and to share this awesome tool around me. π₯³
Do you know any other hidden gems like this that we should use? π
PS. They even released a Web tool if you want to lint your Dockerfiles in your navigator! π₯°
Top comments (1)
Hey @ranb2002 π
There is also a Docker analyzer by DeepSource which lets you continuously analyze
dockerfiles
for issues and also helps you automatically fix most of them.Do give it a try, and let me know your thoughts! π
It is free to use for Open-Source projects.