DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Testcontainers: From Zero To Hero [Video]
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Cloud Build Unleashed: Expert Techniques for CI/CD Optimization
  • Integrating Spring Boot Microservices With MySQL Container Using Docker Desktop

Trending

  • Why AI Forces a Rethink of Everything We Know About Software Security
  • Comparing Top Gen AI Frameworks for Java in 2026
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch
  • The Update Problem REST Doesn't Solve
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Why Lint DockerFile in Continuous Integration?

Why Lint DockerFile in Continuous Integration?

Dockerfile Linter Inspects the commands mentioned in Dockerfiles to build an optimized image. Docker Linter should be given equal weightage as code linter.

By 
Ritresh Girdhar user avatar
Ritresh Girdhar
·
Jun. 29, 20 · Opinion
Likes (4)
Comment
Save
Tweet
Share
8.7K Views

Join the DZone community and get the full member experience.

Join For Free

What Is Linter?

Lint or Linter is a tool that analyses source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.

We often talk about the best practices or syntax to follow while writing source code for the application but we usually skip the code which helps us in generating deployable containers like for docker image we have Dockerfile.


Why We Need Linter?

In the era of Microservices where the concept of Continuous Integration has become a necessity so as to keep application code changes in production-quality state.

Continuous Inspection is another important aspect which ensures the quality of software/application by continuously validating all the changes and identifying the risks before moving the change to production.

Irrespective of the development practice being followed it is always important to integrate Continuous Inspection tool to build cycle.


Common Lint Tools

There are multiple continuous inspection tools available which support more than one programming languages and have multiple features like below:

Sonar Qube— Continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on 20+ programming languages.

 copied from — sonarqube.org



Why We Need Linter for Docker?

There are many linters available which inspect code of different programming languages. But how we should make sure that the docker image generated for our application is in optimised form.

That’s why we need some linter which will inspect and apply all the quality checks on the Dockerfile.

Dockerfile — is a text document that contains all the commands a user could call on the command line to assemble a deployable docker image.


Available Docker Linters

There are many open source docker linters available :

  • Haskell Linter
  • Atom Linter

Here I am using Haskell Docker Linter.

Haskell Docker Linter will inspect the Dockerfile into an AST and performs rules on top of the AST. It additionally is using the famous Shellcheck to lint the Bash code inside RUN instructions.


Integrate Docker Linter — CI Pipeline

Here, I have used Declarative Pipeline for Continuous Integration (CI).

The below code is adding a stage i.e “Quality gate - Dockerfile” before building docker image. It will then inspect the application Dockerfile and archive the result as a text file.

Java
 




x
22


 
1
stages {....
2
stage ("Quality Gate") { 
3

           
4
   parallel {     
5

           
6
      stage ("Dockerfile") {
7
         agent {
8
            docker {
9
               image 'hadolint/hadolint:latest-debian'
10
            }
11
         }
12
         steps {
13
            sh 'hadolint microservice1/dockerfile | tee -a      ms1_docker_lint.txt'
14
         }
15
         post {
16
          always {
17
            archiveArtifacts 'ms1_docker_lint.txt'
18
          }
19
      }
20
  }
21
}
22
....}



Continuous Integration Pipeline

Continuous Integration Pipeline




Thanks for reading!

I hope you have enjoyed reading the article.

Continuous Integration/Deployment Docker (software) Integration Lint (software)

Published at DZone with permission of Ritresh Girdhar. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Testcontainers: From Zero To Hero [Video]
  • Jenkins in the Age of Kubernetes: Strengths, Weaknesses, and Its Future in CI/CD
  • Cloud Build Unleashed: Expert Techniques for CI/CD Optimization
  • Integrating Spring Boot Microservices With MySQL Container Using Docker Desktop

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook