# 一个小工具：Hadolint

[Hadolint](https://github.com/hadolint/hadolint) 是使用不明觉厉的 Haskell 实现的 Dockerfile linter，其实现依据来自于 Docker 官网推荐的 [Dockerfile 最佳实践](https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices)。

在 Mac 下的安装只要使用简单的 `brew install hadolint` 就能够完成安装，其它平台也有各自的支持方式。

用法非常简单：`hadolint <dockerfile>` 即可，例如我们编写一个简单的 Dockerfile：

~~~shell
$ cat << EOF > /tmp/Dockerfile                                                                             master  ✱
heredoc> FROM alpine
heredoc> CMD ["sleep", "3600"]
heredoc> EOF

$ hadolint /tmp/Dockerfile
/tmp/Dockerfile:1 DL3006 Always tag the version of an image explicitly
~~~

可以使用 `--ignore` 参数忽略指定的问题，如果是固定配置，可以使用 `-c` 参数指定配置文件。例如下面的配置：

~~~yaml
ignored:
  - DL3000
  - SC1010

trustedRegistries:
  - docker.io
  - my-company.com:5000
~~~

> 其检测范围包括在 [README](https://github.com/hadolint/hadolint/blob/master/README.md) 有非常详细的描述，并在连接中给出了建议。

hadolint 提供了很多[集成选项](https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md)，可以集成到 Jenkins、Gitlab 等自动化流程中使用，在 vim、VSCode、Atom 编辑器中也可以直接生效。

- README：`https://github.com/hadolint/hadolint/blob/master/README.md`
- 集成选项：`https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md`
