Skip to content

[Linux] How To Use Hadolint To Avoid Terrible Dockerfile

Last Updated on 2024-08-23 by Clay

What is Hadolint?

Hadolint is a Dockerfile linter that helps you follow best practices and style guidelines when writing Dockerfiles.

It is based on Haskell Dockerfile Linter and integrates the functionality of ShellCheck, allowing you to maintain clean and high-quality code while writing Dockerfiles.

In short, the reason we use Hadolint is that when we (developers) create Dockerfiles, our approach may not always follow best practices. Therefore, we can use Hadolint to help us:

  • Follow Docker's best practices
  • Avoid common mistakes and security issues

Installation Methods

  1. Docker
docker pull hadolint/hadolint



  1. Linux
sudo wget -O /usr/local/bin/hadolint https://github.com/hadolint/hadolint/releases/download/v2.6.1/hadolint-Linux-x86_64 &&\
sudo chmod +x /usr/local/bin/hadolint


The version number v2.6.1 is an example; of course, you can use the latest version.


How to use Hadolint?

In the terminal, you can directly pass the path of your Dockerfile to hadolint.

hadolint path_to_your_Dockerfile


You will then see hadolint's suggestions for improvements in your Dockerfile.


References


Read More

Leave a Reply