How to set up hadolint in .devcontainer with Visual Studio Code

Tomomi Sako
2 min readMay 29, 2021
Photo by Ian Taylor on Unsplash

As you can see in the documentation, hadolint is “A smarter Dockerfile linter that helps you build best practice Docker images.”

There is a hadolint VSCode extension here, but if you would like to set up the extension with your .devcontainer you need some “tips”. So I will explain it.

First of all, even we have the VSCode extension of hadolint, we need to install the package manually if you are using .devcontainer. In this example, I am using a Linux-based docker image but if you are using a different OS, please use the appropriate command to install it.

After installing hadolint, we add the hadolint extension to our devcontainer.

After rebuilding the container (or use “Reopen in Container”, if you didn’t open the devcontainer yet), we can see that hadolint is applied so we have warning messages on the Dockerfile.

Not all rules are useful to me, so let’s add a config file to specify the ignored lint rules. First, we create hadolint.yaml in the root and add some rules. In our case, let’s add the rule to ignore the current warnings (DL3008, DL3015).

Once we save it, we no longer see the previous warnings in our Dockerfile!

--

--