Hadolint提升Dockerfile的质量和安全性 —— 筑梦之路

https://github.com/hadolint/hadolint

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

bash 复制代码
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"]
bash 复制代码
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 <package>` use `npm install <package>@<version>`
-:8 DL3011 error: Valid UNIX ports range from 0 to 65535

指定忽略的规则

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

bash 复制代码
ignored:
  - DL3011

运行Hadolint时指定配置文件

bash 复制代码
nerdctl run --rm -i -v /root/hadolint-demo/hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint < Dockerfile
bash 复制代码
-: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 <package>` use `npm install <package>@<version>`

为了确保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

相关推荐
xiaoye-duck1 分钟前
《Linux 网络编程》应用层自定义协议(一):序列化、sk_buff 与粘包半包处理
linux·网络
郭老师-嵌入式6 分钟前
arm linux 移植 udhcp 与 使用
linux·服务器·arm开发
代码终究输给规则7 分钟前
MATLAB r2026a 安装包和安装教程
linux·运维·服务器
临岸草惊风.8 分钟前
简单VASP计算INCAR设置(结构优化OPT、静态自洽SCF、能带BAND、态密度DOS)
linux·dft
钟良堂20 分钟前
Ubuntu 20.04 部署 ORB_SLAM3 完整流程与踩坑总结
linux·运维·ubuntu
张小姐的猫35 分钟前
【Linux】网络编程 —— 手动部署 & 测试内网穿透
linux·运维·服务器·网络·tcp/ip
深念Y42 分钟前
ZTE B860AV1.1-T2 机顶盒改造记录:从 Android 到 Linux 服务器
android·linux·运维·服务器·boot·cma·机顶盒
祖力551 小时前
进程相关的函数与exec函数簇
linux·运维·服务器·进程·exec函数簇·进程相关的函数
Discipline~Hai1 小时前
Linux应用软件编程04-线程
linux·服务器·c语言·开发语言·linux应用软件编程
charlie1145141911 小时前
Cinux · musl 静态移植:对齐 Linux ABI、铺初始栈,以及一个被 SMAP 拦下的潜伏 bug
linux·开发语言·c++·操作系统·开源项目