Hadolint提升Dockerfile的质量和安全性 —— 筑梦之路
创始人
2025-01-10 12:38:16
0

https://github.com/hadolint/hadolint

hadolint 在线版本:https://hadolint.github.io/hadolint/

FROM debian RUN export node_version="0.10" \ && apt-get update && apt-get -y install nodejs="$node_verion" COPY package.json usr/src/app RUN cd /usr/src/app \ && npm install node-static  EXPOSE 80000 CMD ["npm", "start"]
nerdctl run --rm -i hadolint/hadolint < Dockerfile  -:1 DL3006 warning: Always tag the version of an image explicitly -:2 DL3015 info: Avoid additional packages by specifying `--no-install-recommends` -:2 DL3009 info: Delete the apt-get lists after installing something -:2 SC2154 warning: node_verion is referenced but not assigned (did you mean 'node_version'?). -:4 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set. -:5 DL3003 warning: Use WORKDIR to switch to a directory -:5 DL3016 warning: Pin versions in npm. Instead of `npm install ` use `npm install @` -:8 DL3011 error: Valid UNIX ports range from 0 to 65535

指定忽略的规则

如何你想忽略某些规则,在项目目录下创建hadolint.yaml文件,并指定要忽略的规则

ignored:   - DL3011

运行Hadolint时指定配置文件

nerdctl run --rm -i -v /root/hadolint-demo/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint < Dockerfile
-:1 DL3006 warning: Always tag the version of an image explicitly -:2 SC2154 warning: node_verion is referenced but not assigned (did you mean 'node_version'?). -:2 DL3009 info: Delete the apt-get lists after installing something -:2 DL3015 info: Avoid additional packages by specifying `--no-install-recommends` -:4 DL3045 warning: `COPY` to a relative destination without `WORKDIR` set. -:5 DL3003 warning: Use WORKDIR to switch to a directory -:5 DL3016 warning: Pin versions in npm. Instead of `npm install ` use `npm install @`

为了确保Dockerfiles的质量和安全性,将Hadolint集成到开发工作流程中是一个明智之举。这样可以在代码编写、提交前以及持续集成(CI)过程中自动检测潜在问题。以下是一些常见的集成方式:

  • 代码审查平台集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#code-review

  • 持续集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#continuous-integration

  • 编辑器集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#editors

  • 版本控制集成

https://github.com/hadolint/hadolint/blob/master/docs/INTEGRATION.md#version-control

 

相关内容

热门资讯

第7分钟了解(wpk俱乐部)黑... 第7分钟了解(wpk俱乐部)黑科技透明挂辅助app(透视)详细教程(2026已更新)(哔哩哔哩);A...
记者揭秘!"德州之星... 记者揭秘!"德州之星有app辅助"详细外挂透明挂辅助安装-总是存在有挂(哔哩哔哩);1、不需要AI权...
透视美元局!wpk辅助插件(透... 透视美元局!wpk辅助插件(透视)底牌透视挂辅助神器(可靠开挂辅助普及教程)-哔哩哔哩;wpk辅助插...
1.9分钟了解"we... 《1.9分钟了解"wepoke开发者"详细外挂透明挂辅助插件-真是真的有挂(哔哩哔哩)》 wepok...
第十分钟了解(Wepoke程序... 第十分钟了解(Wepoke程序)黑科技透明挂辅助插件(透视)新2025教程(2021已更新)(哔哩哔...
透视了解!pokemmo脚本辅... 透视了解!pokemmo脚本辅助下载(透视)底牌透视挂辅助程序(可靠开挂辅助第三方教程)-哔哩哔哩;...
第一分钟了解(wepoke辅助... 第一分钟了解(wepoke辅助透视)外挂智能ai辅助下载(透视)科技教程(2024已更新)(哔哩哔哩...
教程辅助"微扑克发牌... 教程辅助"微扑克发牌规律性总结"详细外挂透明挂辅助神器-原生有挂(哔哩哔哩);大家肯定在之前微扑克发...
透视透视!hhpoker底牌透... 透视透视!hhpoker底牌透视脚本(透视)底牌透视挂辅助程序(可靠开挂辅助安装教程)-哔哩哔哩;亲...
8分钟了解(aapoker透明... 8分钟了解(aapoker透明挂)外挂透明挂辅助科技(透视)第三方教程(2026已更新)(哔哩哔哩)...