Dockerfile 静态检查工具
hadolint 检查 Dockerfile 的最佳实践和常见错误,内置 ShellCheck 检查 RUN 中的 shell 片段。它只分析 Dockerfile,不分析构建出的镜像。
hadolint Dockerfile
hadolint --format json Dockerfile
hadolint --failure-threshold warning Dockerfile
hadolint --ignore DL3008 Dockerfile
hadolint --config .hadolint.yaml Dockerfile
.hadolint.yaml:
failure-threshold: warning
ignored:
- DL3008
- DL3013
trustedRegistries:
- docker.io
- registry.example.com
--failure-threshold 决定退出码;不设置可能只警告不失败。--ignore 要写清原因,不要为了过 CI 全量忽略。FROM 都会检查;基础镜像也要固定 digest。RUN 里的 shell 片段由 ShellCheck 检查,复杂脚本建议拆成文件。--config。docker-buildx — 构建镜像grype — 镜像漏洞扫描dive — 镜像层分析