Hadolint is a linter for Dockerfiles. It helps to detect security issues, syntax errors in Dockerfiles, and build Docker images that follow best practices. Hadolint is based on ShellCheck, which helps catch errors in shell commands within the Dockerfile. This tutorial demonstrates how to install Hadolint on Ubuntu 24.04.
Install Hadolint
Download the executable to the /usr/local/bin
directory:
sudo wget -qO /usr/local/bin/hadolint https://github.com/hadolint/hadolint/releases/latest/download/hadolint-Linux-x86_64
Set execute permission for file:
sudo chmod a+x /usr/local/bin/hadolint
Run the following command to check the Hadolint version:
hadolint --version
Testing Hadolint
Create Dockerfile for testing purposes:
nano Dockerfile
Add the following content:
FROM ubuntu
RUN apt-get update && apt-get install -y curl
Execute the following command to analyze the Dockerfile:
hadolint Dockerfile
Hadolint will display warnings and recommendations based on best practices:
Dockerfile:1 DL3006 warning: Always tag the version of an image explicitly
Dockerfile:3 DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
Dockerfile:3 DL3015 info: Avoid additional packages by specifying `--no-install-recommends`
Dockerfile:3 DL3009 info: Delete the apt-get lists after installing something
Uninstall Hadolint
To remove Hadolint, delete its corresponding file:
sudo rm -rf /usr/local/bin/hadolint
Leave a Comment
Cancel reply